Video signal encoding and decoding method, and apparatus therefor

ABSTRACT

A video decoding method includes the steps of: generating a merge candidate list for a first block; selecting one among merge candidates included in the merge candidate list; and performing motion compensation for the first block based on motion information of the selected merge candidate. At this point, an inter-region merge candidate included in an inter-region motion information list may be added to the merge candidate list based on the number of spatial merge candidates and temporal merge candidates included in the merge candidate list.

CROSS-REFERENCE

This is a continuation application of U.S. patent application Ser. No.17/205,515, filed on Mar. 18, 2021, which is a continuation applicationof International Patent Application No. PCT/KR2019/012292, filed on Sep.20, 2019, which claims priorities to Korean Patent Application No.10-2018-0114348, filed on Sep. 21, 2018, Korean Patent Application No.10-2018-0114349, filed on Sep. 21, 2018, and Korean Patent ApplicationNo. 10-2018-0148858, filed Nov. 27, 2018, the entire contents of whichare incorporated herein by reference in their entireties.

TECHNICAL FIELD

The present disclosure relates to a video signal encoding and decodingmethod and an apparatus therefor.

BACKGROUND

As display panels are getting bigger and bigger, video services offurther higher quality are required more and more. The biggest problemof high-definition video services is significant increase in datavolume, and to solve this problem, studies for improving the videocompression rate are actively conducted. As a representative example,the Motion Picture Experts Group (MPEG) and the Video Coding ExpertsGroup (VCEG) under the International TelecommunicationUnion-Telecommunication (ITU-T) have formed the Joint Collaborative Teamon Video Coding (JCT-VC) in 2009. The JCT-VC has proposed HighEfficiency Video Coding (HEVC), which is a video compression standardhaving a compression performance about twice as high as the compressionperformance of H.264/AVC, and it is approved as a standard on Jan. 25,2013. With rapid advancement in the high-definition video services,performance of the HEVC gradually reveals its limitations.

SUMMARY Technical Problem

An object of the present disclosure is to provide a method of deriving amerge candidate other than merge candidates derived from candidateblocks adjacent to a current block, and an apparatus for performing themethod, in encoding/decoding a video signal.

Another object of the present disclosure is to provide a method ofderiving merge candidates using an inter-region motion information list,and an apparatus for performing the method, in encoding/decoding a videosignal.

Another object of the present disclosure is to provide a method ofderiving merge candidates of blocks included in a merge processing area,and an apparatus for performing the method, in encoding/decoding a videosignal.

The technical problems to be achieved in the present disclosure are notlimited to the technical problems mentioned above, and unmentioned otherproblems may be clearly understood by those skilled in the art from thefollowing description.

Solution to Problem

A method of decoding/encoding a video signal according to the presentdisclosure includes the steps of: generating a merge candidate list fora first block; selecting any one among merge candidates included in themerge candidate list; and performing motion compensation for the firstblock based on motion information of the selected merge candidate. Atthis point, an inter-region merge candidate included in an inter-regionmotion information list is added to the merge candidate list based onthe number of spatial merge candidates and temporal merge candidatesincluded in the merge candidate list.

In the video signal encoding and decoding method according to thepresent disclosure, the inter-region motion information list may includean inter-region merge candidate derived based on motion information of ablock decoded before the first block. At this point, the inter-regionmotion information list may not be updated based on motion informationof a second block included in a merge processing area the same as thatof the first block.

In the video signal encoding and decoding method according to thepresent disclosure, when the first block is included in a mergeprocessing area, a temporary merge candidate derived based on motioninformation of the first block is added to a temporary motioninformation list, and when decoding of all blocks included in the mergeprocessing area is completed, the temporary merge candidate may beupdated in the inter-region motion information list.

In the video signal encoding and decoding method according to thepresent disclosure, based on a result of determining whether a firstinter-region merge candidate included in the inter-region motioninformation list is the same as at least one merge candidate included inthe merge candidate list, whether or not to add the first inter-regionmerge candidate to the merge candidate list may be determined.

In the video signal encoding and decoding method according to thepresent disclosure, the determination may be performed by comparing atleast one merge candidate of which the index value is smaller than orequal to a threshold value with the first inter-region merge candidate.

In the video signal encoding and decoding method according to thepresent disclosure, when it is determined that there is a mergecandidate the same as the first inter-region merge candidate, the firstinter-region merge candidate is not added to the merge candidate list,and based on a result of determining whether a second inter-region mergecandidate included in the inter-region motion information list is thesame as at least one merge candidate included in the merge candidatelist, whether or not to add the second inter-region merge candidate tothe merge candidate list may be determined. At this point, adetermination as to whether the second inter-region merge candidate isthe same as the merge candidate that is the same as the firstinter-region merge candidate may be omitted.

Features briefly summarized above with respect to the present disclosureare merely exemplary aspects of the detailed description of the presentdisclosure that will be described below, and do not limit the scope ofthe present disclosure.

Advantageous Effects

According to the present disclosure, inter prediction efficiency can beimproved by providing a method of deriving a merge candidate other thanmerge candidates derived from candidate blocks adjacent to a currentblock.

According to the present disclosure, inter prediction efficiency can beimproved by providing a method of deriving merge candidates using aninter-region motion information list.

According to the present disclosure, inter prediction efficiency can beimproved by providing a method of deriving merge candidates of blocksincluded in a merge processing area.

The effects that can be obtained from the present disclosure are notlimited to the effects mentioned above, and unmentioned other effectsmay be clearly understood by those skilled in the art from the followingdescription.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram showing a video encoder according to anembodiment of the present disclosure.

FIG. 2 is a block diagram showing a video decoder according to anembodiment of the present disclosure.

FIG. 3 is a view showing a basic coding tree unit according to anembodiment of the present disclosure.

FIG. 4 is a view showing various partition types of a coding block.

FIG. 5 is a view showing a result of partitioning a coding tree unit.

FIG. 6 is a flowchart illustrating an inter prediction method accordingto an embodiment of the present disclosure.

FIG. 7 is a view showing a nonlinear motion of an object.

FIG. 8 is a flowchart illustrating an inter prediction method based onan affine motion according to an embodiment of the present disclosure.

FIG. 9 is a view showing an example of affine seed vectors of eachaffine motion model.

FIG. 10 is a view showing an example of affine vectors of subblocks in a4-parameter motion model.

FIG. 11 is a flowchart illustrating a process of deriving motioninformation of a current block using a merge mode.

FIG. 12 is a view showing an example of candidate blocks used forderiving a merge candidate.

FIG. 13 is a view showing positions of reference samples.

FIG. 14 is a view showing an example of candidate blocks used forderiving a merge candidate.

FIG. 15 is a view showing an example in which the position of areference sample is changed.

FIG. 16 is a view showing an example in which the position of areference sample is changed.

FIG. 17 is a flowchart illustrating a process of updating aninter-region motion information list.

FIG. 18 is a view showing an embodiment of updating an inter-regionmerge candidate list.

FIG. 19 is a view showing an example in which an index of a previouslystored inter-region merge candidate is updated.

FIG. 20 is a view showing the position of a representative subblock.

FIG. 21 is a view showing an example in which an inter-region motioninformation list is generated for each inter prediction mode.

FIG. 22 is a view showing an example in which an inter-region mergecandidate included in a long-term motion information list is added to amerge candidate list.

FIG. 23 is a view showing an example in which a redundancy check isperformed only on some of merge candidates.

FIG. 24 is a view showing an example in which a redundancy check isomitted for a specific merge candidate.

FIG. 25 is a view showing an example in which candidate blocks includedin the same merge processing area as the current block are set to beunavailable as a merge candidate.

FIG. 26 is a view showing a temporary motion information list.

FIG. 27 is a view showing an example of merging an inter-region motioninformation list and a temporary motion information list.

FIG. 28 is a flowchart illustrating an intra prediction method accordingto an embodiment of the present disclosure.

FIG. 29 is a view showing reference samples included in each referencesample line.

FIG. 30 is a view showing intra prediction modes.

FIG. 31 is a view showing an example of a one-dimensional arrayarranging reference samples in a line.

FIG. 32 is a view showing an example of a one-dimensional arrayarranging reference samples in a line.

FIG. 33 is a view showing an example of angles formed between angularintra prediction modes and a straight line parallel to the x-axis.

FIG. 34 is a view showing an embodiment of acquiring prediction sampleswhen the current block is a non-square shape.

FIG. 35 is a view showing wide-angle intra prediction modes.

FIG. 36 is a view showing an embodiment of applying PDPC.

FIG. 37 is a view showing an example in which a second merge candidateis specified considering a search order of candidate blocks.

FIG. 38 is a view showing an example in which a first merge candidateand a second merge candidate are selected among merge candidates derivedfrom non-neighboring blocks.

FIG. 39 is a view showing an example in which weighting values appliedto prediction blocks are determined based on the shape of candidateblocks.

FIG. 40 is a view showing an example of setting a non-affine mergecandidate, instead of an affine merge candidate, as a second mergecandidate.

FIG. 41 is a view showing an example in which a merge candidate isreplaced.

FIG. 42 is a flowchart illustrating a process of determining blockstrength.

FIG. 43 is a view showing predefined filter candidates.

DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT

Hereafter, an embodiment of the present disclosure will be described indetail with reference to the accompanying drawings.

Encoding and decoding of a video is performed by the unit of block. Forexample, an encoding/decoding process such as transform, quantization,prediction, in-loop filtering, reconstruction or the like may beperformed on a coding block, a transform block, or a prediction block.

Hereinafter, a block to be encoded/decoded will be referred to as a‘current block’. For example, the current block may represent a codingblock, a transform block or a prediction block according to a currentencoding/decoding process step.

In addition, it may be understood that the term ‘unit’ used in thisspecification indicates a basic unit for performing a specificencoding/decoding process, and the term ‘block’ indicates a sample arrayof a predetermined size. Unless otherwise stated, the ‘block’ and ‘unit’may be used to have the same meaning. For example, in an embodimentdescribed below, it may be understood that a coding block and a codingunit have the same meaning.

FIG. 1 is a block diagram showing a video encoder according to anembodiment of the present disclosure.

Referring to FIG. 1 , a video encoding apparatus 100 may include apicture partitioning part 110, a prediction part 120 and 125, atransform part 130, a quantization part 135, a rearrangement part 160,an entropy coding part 165, an inverse quantization part 140, an inversetransform part 145, a filter part 150, and a memory 155.

Each of the components shown in FIG. 1 is independently shown torepresent characteristic functions different from each other in a videoencoding apparatus, and it does not mean that each component is formedby the configuration unit of separate hardware or single software. Thatis, each component is included to be listed as a component forconvenience of explanation, and at least two of the components may becombined to form a single component, or one component may be dividedinto a plurality of components to perform a function. Integratedembodiments and separate embodiments of the components are also includedin the scope of the present disclosure if they do not depart from theessence of the present disclosure.

In addition, some of the components are not essential components thatperform essential functions in the present disclosure, and may beoptional components only for improving performance. The presentdisclosure may be implemented to include only the components essentialto implement the essence of the present disclosure excluding thecomponents used only for improving performance, and a structureincluding only essential components excluding the optional componentsused only for improving performance is also included in the scope of thepresent disclosure.

The picture partitioning part 110 may partition an input picture into atleast one processing unit. At this point, the processing unit may be aprediction unit (PU), a transform unit (TU), or a coding unit (CU). Thepicture partitioning part 110 may partition a picture into a combinationof a plurality of coding units, prediction units, and transform units,and encode a picture by selecting a combination of a coding unit, aprediction unit, and a transform unit based on a predetermined criterion(e.g., a cost function).

For example, one picture may be partitioned into a plurality of codingunits. In order to partition the coding units in a picture, a recursivetree structure such as a quad tree structure may be used. A video or acoding unit partitioned into different coding units using the largestcoding unit as a root may be partitioned to have as many child nodes asthe number of partitioned coding units. A coding unit that is notpartitioned any more according to a predetermined restriction becomes aleaf node. That is, when it is assumed that only square partitioning ispossible for one coding unit, the one coding unit may be partitionedinto up to four different coding units.

Hereinafter, in an embodiment of the present disclosure, the coding unitmay be used as a meaning of a unit performing encoding or a meaning of aunit performing decoding.

The prediction unit may be one that is partitioned in a shape of atleast one square, rectangle or the like of the same size within onecoding unit, or it may be any one prediction unit, among the predictionunits partitioned within one coding unit, that is partitioned to have ashape and/or size different from those of another prediction unit.

If the coding unit is not a smallest coding unit when a prediction unitthat performs intra prediction based on the coding unit is generated,intra prediction may be performed without partitioning a picture into aplurality of prediction units N×N.

The prediction part 120 and 125 may include an inter prediction part 120that performs inter prediction and an intra prediction part 125 thatperforms intra prediction. It may be determined whether to use interprediction or to perform intra prediction for a prediction unit, anddetermine specific information (e.g., intra prediction mode, motionvector, reference picture, etc.) according to each prediction method. Atthis point, a processing unit for performing prediction may be differentfrom a processing unit for determining a prediction method and specificcontent. For example, a prediction method and a prediction mode may bedetermined in a prediction unit, and prediction may be performed in atransform unit. A residual coefficient (residual block) between thereconstructed prediction block and the original block may be input intothe transform part 130. In addition, prediction mode information, motionvector information and the like used for prediction may be encoded bythe entropy coding part 165 together with the residual coefficient andtransferred to a decoder. When a specific encoding mode is used, anoriginal block may be encoded as it is and transmitted to a decoderwithout generating a prediction block through the prediction part 120and 125.

The inter prediction part 120 may predict a prediction unit based oninformation on at least one picture among pictures before or after thecurrent picture, and in some cases, it may predict a prediction unitbased on information on a partial area that has been encoded in thecurrent picture. The inter prediction part 120 may include a referencepicture interpolation part, a motion prediction part, and a motioncompensation part.

The reference picture interpolation part may receive reference pictureinformation from the memory 155 and generate pixel information of aninteger number of pixels or less from the reference picture. In the caseof a luminance pixel, a DCT-based 8-tap interpolation filter with avarying filter coefficient may be used to generate pixel information ofan integer number of pixels or less by the unit of ¼ pixels. In the caseof a color difference signal, a DCT-based 4-tap interpolation filterwith a varying filter coefficient may be used to generate pixelinformation of an integer number of pixels or less by the unit of ⅛pixels.

The motion prediction part may perform motion prediction based on thereference picture interpolated by the reference picture interpolationpart. Various methods such as a full search-based block matchingalgorithm (FBMA), a three-step search (TSS), and a new three-step searchalgorithm (NTS) may be used as a method of calculating a motion vector.The motion vector may have a motion vector value of a unit of ½ or ¼pixels based on interpolated pixels. The motion prediction part maypredict a current prediction unit by varying the motion prediction.Various methods such as a skip mode, a merge mode, an advanced motionvector prediction (AMVP) mode, an intra-block copy mode and the like maybe used as the motion prediction mode.

The intra prediction part 125 may generate a prediction unit based onthe information on reference pixels in the neighborhood of the currentblock, which is pixel information in the current picture. When a blockin the neighborhood of the current prediction unit is a block on whichinter prediction has been performed and thus the reference pixel is apixel on which inter prediction has been performed, the reference pixelincluded in the block on which inter prediction has been performed maybe used in place of reference pixel information of a block in theneighborhood on which intra prediction has been performed. That is, whena reference pixel is unavailable, at least one reference pixel amongavailable reference pixels may be used in place of unavailable referencepixel information.

In the intra prediction, the prediction mode may have an angularprediction mode that uses reference pixel information according to aprediction direction, and a non-angular prediction mode that does notuse directional information when performing prediction. A mode forpredicting luminance information may be different from a mode forpredicting color difference information, and intra prediction modeinformation used to predict luminance information or predicted luminancesignal information may be used to predict the color differenceinformation.

If the size of the prediction unit is the same as the size of thetransform unit when intra prediction is performed, the intra predictionmay be performed for the prediction unit based on a pixel on the leftside, a pixel on the top-left side, and a pixel on the top of theprediction unit. However, if the size of the prediction unit isdifferent from the size of the transform unit when the intra predictionis performed, the intra prediction may be performed using a referencepixel based on the transform unit. In addition, intra prediction usingN×N partitioning may be used only for the smallest coding unit.

The intra prediction method may generate a prediction block afterapplying an Adaptive Intra Smoothing (AIS) filter to the reference pixelaccording to a prediction mode. The type of the AIS filter applied tothe reference pixel may vary. In order to perform the intra predictionmethod, the intra prediction mode of the current prediction unit may bepredicted from the intra prediction mode of the prediction unit existingin the neighborhood of the current prediction unit. When a predictionmode of the current prediction unit is predicted using the modeinformation predicted from the neighboring prediction unit, if the intraprediction modes of the current prediction unit is the same as theprediction unit in the neighborhood, information indicating that theprediction modes of the current prediction unit is the same as theprediction unit in the neighborhood may be transmitted usingpredetermined flag information, and if the prediction modes of thecurrent prediction unit and the prediction unit in the neighborhood aredifferent from each other, prediction mode information of the currentblock may be encoded by performing entropy coding.

In addition, a residual block including a prediction unit that hasperformed prediction based on the prediction unit generated by theprediction part 120 and 125 and residual coefficient information, whichis a difference value of the prediction unit with the original block,may be generated. The generated residual block may be input into thetransform part 130.

The transform part 130 may transform the residual block including theoriginal block and the residual coefficient information of theprediction unit generated through the prediction part 120 and 125 usinga transform method such as Discrete Cosine Transform (DCT), DiscreteSine Transform (DST), or KLT. Whether to apply the DCT, the DST or theKLT to transform the residual block may be determined based on intraprediction mode information of a prediction unit used to generate theresidual block.

The quantization part 135 may quantize values transformed into thefrequency domain by the transform part 130. Quantization coefficientsmay vary according to the block or the importance of a video. A valuecalculated by the quantization part 135 may be provided to the inversequantization part 140 and the rearrangement part 160.

The rearrangement part 160 may rearrange coefficient values for thequantized residual coefficients.

The rearrangement part 160 may change coefficients of a two-dimensionalblock shape into a one-dimensional vector shape through a coefficientscanning method. For example, the rearrangement part 160 may scan DCcoefficients up to high-frequency domain coefficients using a zig-zagscan method, and change the coefficients into a one-dimensional vectorshape. According to the size of the transform unit and the intraprediction mode, a vertical scan of scanning the coefficients of atwo-dimensional block shape in the column direction and a horizontalscan of scanning the coefficients of a two-dimensional block shape inthe row direction may be used instead of the zig-zag scan. That is,according to the size of the transform unit and the intra predictionmode, a scan method that will be used may be determined among thezig-zag scan, the vertical direction scan, and the horizontal directionscan.

The entropy coding part 165 may perform entropy coding based on valuescalculated by the rearrangement part 160. Entropy coding may use variousencoding methods such as Exponential Golomb, Context-Adaptive VariableLength Coding (CAVLC), Context-Adaptive Binary Arithmetic Coding(CABAC), and the like.

The entropy coding part 165 may encode various information such asresidual coefficient information and block type information of a codingunit, prediction mode information, partitioning unit information,prediction unit information and transmission unit information, motionvector information, reference frame information, block interpolationinformation, and filtering information input from the rearrangement part160 and the prediction parts 120 and 125.

The entropy coding part 165 may entropy-encode the coefficient value ofa coding unit input from the rearrangement part 160.

The inverse quantization part 140 and the inverse transform part 145inverse-quantize the values quantized by the quantization part 135 andinverse-transform the values transformed by the transform part 130. Theresidual coefficient generated by the inverse quantization part 140 andthe inverse transform part 145 may be combined with the prediction unitpredicted through a motion estimation part, a motion compensation part,and an intra prediction part included in the prediction part 120 and 125to generate a reconstructed block.

The filter part 150 may include at least one among a deblocking filter,an offset compensation unit, and an adaptive loop filter (ALF).

The deblocking filter may remove block distortion generated by theboundary between blocks in the reconstructed picture. In order todetermine whether or not to perform deblocking, whether or not to applythe deblocking filter to the current block may be determined based onthe pixels included in several columns or rows included in the block. Astrong filter or a weak filter may be applied according to thedeblocking filtering strength needed when the deblocking filter isapplied to a block. In addition, when vertical direction filtering andhorizontal direction filtering are performed in applying the deblockingfilter, horizontal direction filtering and vertical direction filteringmay be processed in parallel.

The offset correction unit may correct an offset to the original videoby the unit of pixel for a video on which the deblocking has beenperformed. In order to perform offset correction for a specific picture,it is possible to use a method of dividing pixels included in the videointo a certain number of areas, determining an area to perform offset,and applying the offset to the area, or a method of applying an offsetin consideration of edge information of each pixel.

Adaptive Loop Filtering (ALF) may be performed based on a value obtainedby comparing the reconstructed and filtered video with the originalvideo. After dividing the pixels included in the video intopredetermined groups, one filter to be applied to a corresponding groupmay be determined, and filtering may be performed differently for eachgroup. A luminance signal, which is the information related to whetheror not to apply ALF, may be transmitted for each coding unit (CU), andthe shape and filter coefficient of an ALF filter to be applied may varyaccording to each block. In addition, an ALF filter of the same type(fixed type) may be applied regardless of the characteristic of a blockto be applied.

The memory 155 may store the reconstructed block or picture calculatedthrough the filter part 150, and the reconstructed and stored block orpicture may be provided to the prediction part 120 and 125 when interprediction is performed.

FIG. 2 is a block diagram showing a video decoder according to anembodiment of the present disclosure.

Referring to FIG. 2 , a video decoder 200 may include an entropydecoding part 210, a rearrangement part 215, an inverse quantizationpart 220, an inverse transform part 225, a prediction part 230 and 235,a filter part 240, and a memory 245.

When a video bitstream is input from a video encoder, the inputbitstream may be decoded in a procedure opposite to that of the videoencoder.

The entropy decoding part 210 may perform entropy decoding in aprocedure opposite to that of performing entropy coding in the entropydecoding part of the video encoder. For example, various methodscorresponding to the method performed by the video encoder, such asExponential Golomb, Context-Adaptive Variable Length Coding (CAVLC), andContext-Adaptive Binary Arithmetic Coding (CABAC), may be applied.

The entropy decoding part 210 may decode information related to intraprediction and inter prediction performed by the encoder.

The rearrangement part 215 may perform rearrangement on the bitstreamentropy-decoded by the entropy decoding part 210 based on therearrangement method performed by the encoder. The coefficientsexpressed in a one-dimensional vector shape may be reconstructed andrearranged as coefficients of two-dimensional block shape. Therearrangement part 215 may receive information related to coefficientscanning performed by the encoding part and perform reconstructionthrough a method of inverse-scanning based on the scanning orderperformed by the corresponding encoding part.

The inverse quantization part 220 may perform inverse quantization basedon a quantization parameter provided by the encoder and a coefficientvalue of the rearranged block.

The inverse transform part 225 may perform inverse transform, i.e.,inverse DCT, inverse DST, or inverse KLT, for the transform, i.e., DCT,DST, or KLT, performed by the transform part on a result of thequantization performed by the video encoder. The inverse transform maybe performed based on a transmission unit determined by the videoencoder. The inverse transform part 225 of the video decoder mayselectively perform a transform technique (e.g., DCT, DST, KLT)according to a plurality of pieces of information such as a predictionmethod, a size of a current block, a prediction direction and the like.

The prediction part 230 and 235 may generate a prediction block based oninformation related to generation of a prediction block provided by theentropy decoder 210 and information on a previously decoded block orpicture provided by the memory 245.

As described above, if the size of the prediction unit and the size ofthe transform unit are the same when intra prediction is performed inthe same manner as the operation of the video encoder, intra predictionis performed on the prediction unit based on the pixel existing on theleft side, the pixel on the top-left side, and the pixel on the top ofthe prediction unit. However, if the size of the prediction unit and thesize of the transform unit are different when intra prediction isperformed, intra prediction may be performed using a reference pixelbased on a transform unit. In addition, intra prediction using N×Npartitioning may be used only for the smallest coding unit.

The prediction part 230 and 235 may include a prediction unitdetermination part, an inter prediction part, and an intra predictionpart. The prediction unit determination part may receive variousinformation such as prediction unit information input from the entropydecoding part 210, prediction mode information of the intra predictionmethod, information related to motion prediction of an inter predictionmethod, and the like, identify the prediction unit from the currentcoding unit, and determine whether the prediction unit performs interprediction or intra prediction. The inter prediction part 230 mayperform inter prediction on the current prediction unit based oninformation included in at least one picture among pictures before orafter the current picture including the current prediction unit by usinginformation necessary for inter prediction of the current predictionunit provided by the video encoder. Alternatively, the inter predictionpart 230 may perform inter prediction based on information on a partialarea previously reconstructed in the current picture including thecurrent prediction unit.

In order to perform inter prediction, it may be determined, based on thecoding unit, whether the motion prediction method of the prediction unitincluded in a corresponding coding unit is a skip mode, a merge mode, amotion vector prediction mode (AMVP mode), or an intra-block copy mode.

The intra prediction part 235 may generate a prediction block based onthe information on the pixel in the current picture. When the predictionunit is a prediction unit that has performed intra prediction, the intraprediction may be performed based on intra prediction mode informationof the prediction unit provided by the video encoder. The intraprediction part 235 may include an Adaptive Intra Smoothing (AIS)filter, a reference pixel interpolation part, and a DC filter. The AISfilter is a part that performs filtering on the reference pixel of thecurrent block, and may determine whether or not to apply the filteraccording to the prediction mode of the current prediction unit andapply the filter. AIS filtering may be performed on the reference pixelof the current block by using the prediction mode and AIS filterinformation of the prediction unit provided by the video encoder. Whenthe prediction mode of the current block is a mode that does not performAIS filtering, the AIS filter may not be applied.

When the prediction mode of the prediction unit is a prediction unitthat performs intra prediction based on a pixel value obtained byinterpolating the reference pixel, the reference pixel interpolationpart may generate a reference pixel of a pixel unit having an integervalue or less by interpolating the reference pixel. When the predictionmode of the current prediction unit is a prediction mode that generatesa prediction block without interpolating the reference pixel, thereference pixel may not be interpolated. The DC filter may generate aprediction block through filtering when the prediction mode of thecurrent block is the DC mode.

The reconstructed block or picture may be provided to the filter part240. The filter part 240 may include a deblocking filter, an offsetcorrection unit, and an ALF.

Information on whether a deblocking filter is applied to a correspondingblock or picture and information on whether a strong filter or a weakfilter is applied when a deblocking filter is applied may be provided bythe video encoder. The deblocking filter of the video decoder may beprovided with information related to the deblocking filter provided bythe video encoder, and the video decoder may perform deblockingfiltering on a corresponding block.

The offset correction unit may perform offset correction on thereconstructed video based on the offset correction type and offset valueinformation applied to the video when encoding is performed.

The ALF may be applied to a coding unit based on information on whetheror not to apply the ALF and information on ALF coefficients provided bythe encoder. The ALF information may be provided to be included in aspecific parameter set.

The memory 245 may store the reconstructed picture or block and use itas a reference picture or a reference block and may provide thereconstructed picture to an output unit.

FIG. 3 is a view showing a basic coding tree unit according to anembodiment of the present disclosure.

A coding block of a maximum size may be defined as a coding tree block.A picture is partitioned into a plurality of coding tree units (CTUs).The coding tree unit is a coding unit having a maximum size and may bereferred to as a Large Coding Unit (LCU). FIG. 3 shows an example inwhich a picture is partitioned into a plurality of coding tree units.

The size of the coding tree unit may be defined at a picture level or asequence level. To this end, information indicating the size of thecoding tree unit may be signaled through a picture parameter set or asequence parameter set.

For example, the size of the coding tree unit for the entire picture ina sequence may be set to 128×128. Alternatively, at the picture level,any one among 128×128 and 256×256 may be determined as the size of thecoding tree unit. For example, the size of the coding tree unit may beset to 128×128 in a first picture, and the size of the coding tree unitmay be set to 256×256 in a second picture.

Coding blocks may be generated by partitioning a coding tree unit. Thecoding block indicates a basic unit for performing encoding/decoding.For example, prediction or transform may be performed for each codingblock, or a prediction encoding mode may be determined for each codingblock. Here, the prediction encoding mode indicates a method ofgenerating a prediction picture. For example, the prediction encodingmode may include prediction within a picture (intra prediction),prediction between pictures (inter prediction), current picturereferencing (CPR) or intra-block copy (IBC), or combined prediction. Forthe coding block, a prediction block may be generated by using at leastone prediction encoding mode among the intra prediction, the interprediction, the current picture referencing, and the combinedprediction.

Information indicating the prediction encoding mode of the current blockmay be signaled through a bitstream. For example, the information may bea 1-bit flag indicating whether the prediction encoding mode is an intramode or an inter mode. Only when the prediction encoding mode of thecurrent block is determined as the inter mode, the current picturereferencing or the combined prediction may be used.

The current picture reference is for setting the current picture as areference picture and obtaining a prediction block of the current blockfrom an area that has already been encoded/decoded in the currentpicture. Here, the current picture means a picture including the currentblock. Information indicating whether the current picture reference isapplied to the current block may be signaled through a bitstream. Forexample, the information may be a 1-bit flag. When the flag is true, theprediction encoding mode of the current block may be determined as thecurrent picture reference, and when the flag is false, the predictionmode of the current block may be determined as inter prediction.

Alternatively, the prediction encoding mode of the current block may bedetermined based on a reference picture index. For example, when thereference picture index indicates the current picture, the predictionencoding mode of the current block may be determined as the currentpicture reference. When the reference picture index indicates a pictureother than the current picture, the prediction encoding mode of thecurrent block may be determined as inter prediction. That is, thecurrent picture reference is a prediction method using information on anarea in which encoding/decoding has been completed in the currentpicture, and inter prediction is a prediction method using informationon another picture in which the encoding/decoding has been completed.

The combined prediction represents an encoding mode in which two or moreamong the intra prediction, the inter prediction, and the currentreference picture are combined. For example, when the combinedprediction is applied, a first prediction block may be generated basedon one among the intra prediction, the inter prediction, and the currentpicture referencing, and a second prediction block may be generatedbased on another one. When the first prediction block and the secondprediction block are generated, a final prediction block may begenerated through an average operation or a weighted sum operation ofthe first prediction block and the second prediction block. Informationindicating whether or not the combined prediction is applied may besignaled through a bitstream. The information may be a 1-bit flag.

FIG. 4 is a view showing various partition types of a coding block.

The coding block may be partitioned into a plurality of coding blocksbased on quad tree partitioning, binary tree partitioning, or ternarytree partitioning. The partitioned coding block may be partitioned againinto a plurality of coding blocks based on the quad tree partitioning,the binary tree partitioning, or the ternary tree partitioning.

The quad tree partitioning refers to a partitioning technique thatpartitions a current block into four blocks. As a result of the quadtree partitioning, the current block may be partitioned into foursquare-shaped partitions (see ‘SPLIT_QT’ of FIG. 4 (a)).

The binary tree partitioning refers to a partitioning technique thatpartitions a current block into two blocks. Partitioning a current blockinto two blocks along the vertical direction (i.e., using a verticalline crossing the current block) may be referred to as verticaldirection binary tree partitioning, and partitioning a current blockinto two blocks along the horizontal direction (i.e., using a horizontalline crossing the current block) may be referred to as horizontaldirection binary tree partitioning. As a result of the binary treepartitioning, the current block may be partitioned into two non-squareshaped partitions. ‘SPLIT_BT_VER’ of FIG. 4 (b) shows a result of thevertical direction binary tree partitioning, and ‘SPLIT_BT_HOR’ of FIG.4 (c) shows a result of the horizontal direction binary treepartitioning.

The ternary tree partitioning refers to a partitioning technique thatpartitions a current block into three blocks. Partitioning a currentblock into three blocks along the vertical direction (i.e., using twovertical lines crossing the current block) may be referred to asvertical direction ternary tree partitioning, and partitioning a currentblock into three blocks along the horizontal direction (i.e., using twohorizontal lines crossing the current block) may be referred to ashorizontal direction ternary tree partitioning. As a result of theternary tree partitioning, the current block may be partitioned intothree non-square shaped partitions. At this point, the width/height of apartition positioned at the center of the current block may be twice aslarge as the width/height of the other partitions. ‘SPLIT_TT_VER’ ofFIG. 4 (d) shows a result of the vertical direction ternary treepartitioning, and ‘SPLIT_TT_HOR’ of FIG. 4 (e) shows a result of thehorizontal direction ternary tree partitioning.

The number of times of partitioning a coding tree unit may be defined asa partitioning depth. The maximum partitioning depth of a coding treeunit may be determined at the sequence or picture level. Accordingly,the maximum partitioning depth of a coding tree unit may be differentfor each sequence or picture.

Alternatively, the maximum partitioning depth for each partitioningtechnique may be individually determined. For example, the maximumpartitioning depth allowed for the quad tree partitioning may bedifferent from the maximum partitioning depth allowed for the binarytree partitioning and/or the ternary tree partitioning.

The encoder may signal information indicating at least one among thepartitioning type and the partitioning depth of the current blockthrough a bitstream. The decoder may determine the partitioning type andthe partitioning depth of a coding tree unit based on the informationparsed from the bitstream.

FIG. 5 is a view showing a result of partitioning a coding tree unit.

Partitioning a coding block using a partitioning technique such as quadtree partitioning, binary tree partitioning, and/or ternary treepartitioning may be referred to as multi-tree partitioning.

Coding blocks generated by applying the multi-tree partitioning to acoding block may be referred to as lower coding blocks. When thepartitioning depth of a coding block is k, the partitioning depth of thelower coding blocks is set to k+1.

Contrarily, for coding blocks having a partitioning depth of k+1, acoding block having a partitioning depth of k may be referred to as anupper coding block.

The partitioning type of the current coding block may be determinedbased on at least one among a partitioning type of an upper coding blockand a partitioning type of a neighboring coding block. Here, theneighboring coding block is a coding block adjacent to the currentcoding block and may include at least one among a top neighboring blockand a left neighboring block of the current coding block, and aneighboring block adjacent to the top-left corner. Here, thepartitioning type may include at least one among whether or not a quadtree partitioning, whether or not a binary tree partitioning, binarytree partitioning direction, whether or not a ternary tree partitioning,and ternary tree partitioning direction.

In order to determine a partitioning type of a coding block, informationindicating whether or not the coding block can be partitioned may besignaled through a bitstream. The information is a 1-bit flag of‘split_cu_flag’, and when the flag is true, it indicates that the codingblock is partitioned by a quad tree partitioning technique.

When split_cu_flag is true, information indicating whether the codingblock is quad-tree partitioned may be signaled through a bitstream. Theinformation is a 1-bit flag of split_qt_flag, and when the flag is true,the coding block may be partitioned into four blocks.

For example, in the example shown in FIG. 5 , as a coding tree unit isquad-tree partitioned, four coding blocks having a partitioning depth of1 are generated. In addition, it is shown that quad tree partitioning isapplied again to the first and fourth coding blocks among the fourcoding blocks generated as a result of the quad tree partitioning. As aresult, four coding blocks having a partitioning depth of 2 may begenerated.

In addition, coding blocks having a partitioning depth of 3 may begenerated by applying the quad tree partitioning again to a coding blockhaving a partitioning depth of 2.

When quad tree partitioning is not applied to the coding block, whetherbinary tree partitioning or ternary tree partitioning is performed onthe coding block may be determined in consideration of at least oneamong the size of the coding block, whether the coding block ispositioned at the picture boundary, the maximum partitioning depth, andthe partitioning type of a neighboring block. When it is determined toperform binary tree partitioning or ternary tree partitioning on thecoding block, information indicating the partitioning direction may besignaled through a bitstream. The information may be a 1-bit flag ofmtt_split_cu_vertical_flag. Based on the flag, whether the partitioningdirection is a vertical direction or a horizontal direction may bedetermined. Additionally, information indicating whether binary treepartitioning or ternary tree partitioning is applied to the coding blockmay be signaled through a bitstream. The information may be a 1-bit flagof mtt_split_cu_binary_flag. Based on the flag, whether binary treepartitioning or ternary tree partitioning is applied to the coding blockmay be determined.

For example, in the example shown in FIG. 5 , it is shown that verticaldirection binary tree partitioning is applied to a coding block having apartitioning depth of 1, vertical direction ternary tree partitioning isapplied to the left-side coding block among the coding blocks generatedas a result of the partitioning, and vertical direction binary treepartitioning is applied to the right-side coding block.

Inter prediction is a prediction encoding mode that predicts a currentblock by using information of a previous picture. For example, a blockat the same position as the current block in the previous picture(hereinafter, a collocated block) may be set as the prediction block ofthe current block. Hereinafter, a prediction block generated based on ablock at the same position as the current block will be referred to as acollocated prediction block.

Contrarily, when an object existing in the previous picture has moved toanother position in the current picture, the current block may beeffectively predicted by using a motion of the object. For example, whenthe moving direction and the size of an object can be known by comparingthe previous picture and the current picture, a prediction block (or aprediction picture) of the current block may be generated inconsideration of motion information of the object. Hereinafter, theprediction block generated using motion information may be referred toas a motion prediction block.

A residual block may be generated by subtracting the prediction blockfrom the current block. At this point, when there is a motion of anobject, the energy of the residual block may be reduced by using themotion prediction block instead of the collocated prediction block, andtherefore, compression performance of the residual block can beimproved.

As described above, generating a prediction block by using motioninformation may be referred to as motion compensation prediction. Inmost inter prediction, a prediction block may be generated based on themotion compensation prediction.

The motion information may include at least one among a motion vector, areference picture index, a prediction direction, and a bidirectionalweight index. The motion vector represents the moving direction and thesize of an object. The reference picture index specifies a referencepicture of the current block among reference pictures included in areference picture list. The prediction direction indicates any one amongunidirectional L0 prediction, unidirectional L1 prediction, andbidirectional prediction (L0 prediction and L1 prediction). According tothe prediction direction of the current block, at least one among motioninformation in the L0 direction and motion information in the L1direction may be used. The bidirectional weight index specifies aweighting value applied to a L0 prediction block and a weighting valueapplied to a L1 prediction block.

FIG. 6 is a flowchart illustrating an inter prediction method accordingto an embodiment of the present disclosure.

Referring to FIG. 6 , the inter prediction method includes the steps ofdetermining an inter prediction mode of a current block (S601),acquiring motion information of the current block according to thedetermined inter prediction mode (S602), and performing motioncompensation prediction for the current block based on the acquiredmotion information (S603).

Here, the inter prediction mode represents various techniques fordetermining motion information of the current block, and may include aninter prediction mode that uses translational motion information and aninter prediction mode that uses affine motion information. For example,the inter prediction mode using translational motion information mayinclude a merge mode and a motion vector prediction mode, and the interprediction mode using affine motion information may include an affinemerge mode and an affine motion vector prediction mode. The motioninformation of the current block may be determined based on aneighboring block adjacent to the current block or information parsedfrom a bitstream according to the inter prediction mode.

Hereinafter, the inter prediction method using affine motion informationwill be described in detail.

FIG. 7 is a view showing a nonlinear motion of an object.

A nonlinear motion of an object may be generated in a video. Forexample, as shown in the example of FIG. 7 , a nonlinear motion of anobject, such as zoom-in, zoom-out, rotation, affine transform or thelike of a camera, may occur. When a nonlinear motion of an objectoccurs, the motion of the object cannot be effectively expressed with atranslational motion vector. Accordingly, encoding efficiency can beimproved by using an affine motion instead of a translational motion inan area where a nonlinear motion of an object occurs.

FIG. 8 is a flowchart illustrating an inter prediction method based onan affine motion according to an embodiment of the present disclosure.

Whether an inter prediction technique based on an affine motion isapplied to the current block may be determined based on the informationparsed from a bitstream. Specifically, whether the inter predictiontechnique based on an affine motion is applied to the current block maybe determined based on at least one among a flag indicating whether theaffine merge mode is applied to the current block and a flag indicatingwhether the affine motion vector prediction mode is applied to thecurrent block.

When the inter prediction technique based on an affine motion is appliedto the current block, an affine motion model of the current block may bedetermined (S801). The affine motion model may be determined as at leastone among a six-parameter affine motion model and a four-parameteraffine motion model. The six-parameter affine motion model expresses anaffine motion using six parameters, and the four-parameter affine motionmodel expresses an affine motion using four parameters.

Equation 1 expresses an affine motion using six parameters. The affinemotion represents a translational motion for a predetermined areadetermined by affine seed vectors.v _(x) =ax−by+ev _(y) =cx+dy+f  [Equation 1]

When an affine motion is expressed using six parameters, a complicatedmotion can be expressed. However, as the number of bits required forencoding each of the parameters increases, encoding efficiency may belowered. Accordingly, the affine motion may be expressed using fourparameters. Equation 2 expresses an affine motion using four parameters.v _(x) =ax−by+ev _(y) =bx+ay+f  [Equation 2]

Information for determining an affine motion model of the current blockmay be encoded and signaled through a bitstream. For example, theinformation may be a 1-bit flag of ‘affine_type_flag’. When the value ofthe flag is 0, it may indicate that a 4-parameter affine motion model isapplied, and when the value of the flag is 1, it may indicate that a6-parameter affine motion model is applied. The flag may be encoded bythe unit of slice, tile, or block (e.g., by the unit of coding block orcoding tree). When a flag is signaled at the slice level, an affinemotion model determined at the slice level may be applied to all blocksbelonging to the slice.

Alternatively, an affine motion model of the current block may bedetermined based on an affine inter prediction mode of the currentblock. For example, when the affine merge mode is applied, the affinemotion model of the current block may be determined as a 4-parametermotion model. Contrarily, when the affine motion vector prediction modeis applied, information for determining the affine motion model of thecurrent block may be encoded and signaled through a bitstream. Forexample, when the affine motion vector prediction mode is applied to thecurrent block, the affine motion model of the current block may bedetermined based on the 1-bit flag of ‘affine_type_flag’.

Next, an affine seed vector of the current block may be derived (S802).When a 4-parameter affine motion model is selected, motion vectors attwo control points of the current block may be derived. Contrarily, whena 6-parameter affine motion model is selected, motion vectors at threecontrol points of the current block may be derived. The motion vector ata control point may be referred to as an affine seed vector. The controlpoint may include at least one among the top-left corner, the top-rightcorner, and the bottom-left corner of the current block.

FIG. 9 is a view showing an example of affine seed vectors of eachaffine motion model.

In the 4-parameter affine motion model, affine seed vectors may bederived for two among the top-left corner, the top-right corner, and thebottom-left corner. For example, as shown in the example of FIG. 9 (a),when a 4-parameter affine motion model is selected, an affine vector maybe derived using the affine seed vector sv₀ for the top-left corner ofthe current block (e.g., top-left sample (x1, y1)) and the affine seedvector sv₁ for the top-right corner of the current block (e.g., thetop-right sample (x1, y1)). It is also possible to use an affine seedvector for the bottom-left corner instead of the affine seed vector forthe top-left corner, or use an affine seed vector for the bottom-leftcorner instead of the affine seed vector for the top-right corner.

In the 6-parameter affine motion model, affine seed vectors may bederived for the top-left corner, the top-right corner, and thebottom-left corner. For example, as shown in the example of FIG. 9 (b),when a 6-parameter affine motion model is selected, an affine vector maybe derived using the affine seed vector sv₀ for the top-left corner ofthe current block (e.g., top-left sample (x1, y1)), the affine seedvector sv₁ for the top-right corner of the current block (e.g., thetop-right sample (x1, y1)), and the affine seed vector sv₂ for thetop-left corner of the current block (e.g., top-left sample (x2, y2)).

In the embodiment described below, in the 4-parameter affine motionmodel, the affine seed vectors of the top-left control point and thetop-right control point will be referred to as a first affine seedvector and a second affine seed vector, respectively. In the embodimentsusing the first affine seed vector and the second affine seed vectordescribed below, at least one among the first affine seed vector and thesecond affine seed vector may be replaced by the affine seed vector ofthe bottom-left control point (a third affine seed vector) or the affineseed vector of the bottom-right control point (a fourth affine seedvector).

In addition, in the 6-parameter affine motion model, the affine seedvectors of the top-left control point, the top-right control point, andthe bottom-left control point will be referred to as a first affine seedvector, a second affine seed vector, and a third affine seed vector,respectively. In the embodiments using the first affine seed vector, thesecond affine seed vector, and the third affine seed vector describedbelow, at least one among the first affine seed vector, the secondaffine seed vector, and the third affine seed vector may be replaced bythe affine seed vector of the bottom-right control point (a fourthaffine seed vector).

An affine vector may be derived for each subblock by using the affineseed vectors (S803). Here, the affine vector represents a translationalmotion vector derived based on the affine seed vectors. The affinevector of a subblock may be referred to as an affine subblock motionvector or a subblock motion vector.

FIG. 10 is a view showing an example of affine vectors of subblocks in a4-parameter motion model.

The affine vector of the subblock may be derived based on the positionof the control point, the position of the subblock, and the affine seedvector. For example, Equation 3 shows an example of deriving an affinesubblock vector.

$\begin{matrix}{v_{x} = {{\frac{\left( {{sv_{1x}} - {sv_{0x}}} \right)}{\left( {x_{1} - x_{0}} \right)}\left( {x - x_{0}} \right)} - {\frac{\left( {{sv_{1y}} - {sv_{0y}}} \right)}{\left( {x_{1} - x_{0}} \right)}\left( {y - y_{0}} \right)} + {sv_{0x}}}} & \left\lbrack {{Equation}3} \right\rbrack\end{matrix}$$v_{y} = {{\frac{\left( {{sv_{1y}} - {sv_{0y}}} \right)}{\left( {x_{1} - x_{0}} \right)}\left( {x - x_{0}} \right)} - {\frac{\left( {{sv_{1x}} - {sv_{0x}}} \right)}{\left( {x_{1} - x_{0}} \right)}\left( {y - y_{0}} \right)} + {sv_{0y}}}$

In Equation 3, (x, y) denotes the position of a subblock. Here, theposition of a subblock indicates the position of a reference sampleincluded in the subblock. The reference sample may be a samplepositioned at the top-left corner of the subblock, or a sample of whichat least one among the x-axis and y-axis coordinates is a center point.(x₀, y₀) denotes the position of the first control point, and (sv_(0x),sv_(0y)) denotes the first affine seed vector. In addition, (x₁, y₁)denotes the position of the second control point, and (sv_(1x), sv_(1y))denotes the second affine seed vector.

When the first control point and the second control point correspond tothe top-left corner and the top-right corner of the current blockrespectively, x₁-x₀ may be set to a value equal to the width of thecurrent block.

Thereafter, motion compensation prediction for each subblock may beperformed using the affine vector of each subblock (S804). As a resultof performing the motion compensation prediction, a prediction block foreach subblock may be generated. The prediction blocks of the subblocksmay be set as the prediction blocks of the current block.

Next, an inter prediction method using translational motion informationwill be described in detail.

Motion information of the current block may be derived from motioninformation of another block. Here, another block may be a blockencoded/decoded by inter prediction before the current block. Settingthe motion information of the current block to be equal to the motioninformation of another block may be defined as a merge mode. Inaddition, setting the motion vector of another block as the predictionvalue of the motion vector of the current block may be defined as amotion vector prediction mode.

FIG. 11 is a flowchart illustrating a process of deriving motioninformation of a current block using a merge mode.

A merge candidate of the current block may be derived (S1101). The mergecandidate of the current block may be derived from a blockencoded/decoded by inter prediction before the current block.

FIG. 12 is a view showing an example of candidate blocks used forderiving a merge candidate.

The candidate blocks may include at least one among neighboring blocksincluding a sample adjacent to the current block or non-neighboringblocks including a sample not adjacent to the current block.Hereinafter, samples for determining candidate blocks are defined asreference samples. In addition, a reference sample adjacent to thecurrent block is referred to as a neighboring reference sample, and areference sample not adjacent to the current block is referred to as anon-neighboring reference sample.

The neighboring reference sample may be included in a neighboring columnof the leftmost column of the current block or a neighboring row of theuppermost row of the current block. For example, when the coordinates ofthe top-left sample of the current block is (0, 0), at least one among ablock including a reference sample at the position of (−1, H−1), a blockincluding a reference sample at the position of (W−1, −1), a blockincluding a reference sample at the position of (W, −1), a blockincluding a reference sample at the position of (−1, H), and a blockincluding a reference sample at the position of (−1, −1) may be used asa candidate block. Referring to the drawing, neighboring blocks of index0 to 4 may be used as candidate blocks.

The non-neighboring reference sample represents a sample of which atleast one among an x-axis distance and a y-axis distance from areference sample adjacent to the current block has a predefined value.For example, at least one among a block including a reference sample ofwhich the x-axis distance from the left reference sample is a predefinedvalue, a block including a non-neighboring sample of which the y-axisdistance from the top reference sample is a predefined value, and ablock including a non-neighboring sample of which the x-axis distanceand the y-axis distance from the top-left reference sample arepredefined values may be used as a candidate block. The predefinedvalues may be a natural number such as 4, 8, 12, 16 or the like.Referring to the drawing, at least one among the blocks of index 5 to 26may be used as a candidate block.

A sample not positioned on the same vertical line, horizontal line, ordiagonal line as the neighboring reference sample may be set as anon-neighboring reference sample.

FIG. 13 is a view showing positions of reference samples.

As shown in the example of FIG. 13 , the x coordinates of the topnon-neighboring reference samples may be set to be different from the xcoordinates of the top neighboring reference samples. For example, whenthe position of the top neighboring reference sample is (W−1, −1), theposition of a top non-neighboring reference sample separated as much asN from the top neighboring reference sample on the y-axis may be set to((W/2)−1, −1−N), and the position of a top non-neighboring referencesample separated as much as 2N from the top neighboring reference sampleon the y-axis may be set to (0, −1−2N). That is, the position of anon-neighboring reference sample may be determined based on the positionof a neighboring reference sample and a distance from the neighboringreference sample.

Hereinafter, a candidate block including a neighboring reference sampleamong the candidate blocks is referred to as a neighboring block, and ablock including a non-neighboring reference sample is referred to as anon-neighboring block.

When the distance between the current block and the candidate block isgreater than or equal to a threshold value, the candidate block may beset to be unavailable as a merge candidate. The threshold value may bedetermined based on the size of the coding tree unit. For example, thethreshold value may be set to the height (ctu_height) of the coding treeunit or a value obtained by adding or subtracting an offset to or fromthe height (e.g., ctu_height±N) of the coding tree unit. The offset N isa value predefined in the encoder and the decoder, and may be set to 4,8, 16, 32 or ctu_height.

When the difference between the y-axis coordinate of the current blockand the y-axis coordinate of a sample included in a candidate block isgreater than the threshold value, the candidate block may be determinedto be unavailable as a merge candidate.

Alternatively, a candidate block that does not belong to the same codingtree unit as the current block may be set to be unavailable as a mergecandidate. For example, when a reference sample deviates from the topboundary of a coding tree unit to which the current block belongs, acandidate block including the reference sample may be set to beunavailable as a merge candidate.

When the top boundary of the current block is adjacent to the topboundary of the coding tree unit, a plurality of candidate blocks isdetermined to be unavailable as a merge candidate, and thus theencoding/decoding efficiency of the current block may decrease. To solvethis problem, candidate blocks may be set so that the number ofcandidate blocks positioned on the left side of the current block isgreater than the number of candidate blocks positioned on the top of thecurrent block.

FIG. 14 is a view showing an example of candidate blocks used forderiving a merge candidate.

As shown in the example of FIG. 14 , top blocks belonging to top N blockcolumns of the current block and left-side blocks belonging to Mleft-side block columns of the current block may be set as candidateblocks. At this point, the number of left-side candidate blocks may beset to be greater than the number of top candidate blocks by setting Mto be greater than N.

For example, the difference between the y-axis coordinate of thereference sample in the current block and the y-axis coordinate of thetop block that can be used as a candidate block may be set not to exceedN times of the height of the current block. In addition, the differencebetween the x-axis coordinate of the reference sample in the currentblock and the x-axis coordinate of the left-side block that can be usedas a candidate block may be set not to exceed M times of the width ofthe current block.

For example, in the example shown in FIG. 14 , it is shown that blocksbelonging to the top two block columns of the current block and blocksbelonging to the left five block columns of the current block are set ascandidate blocks.

As another example, when a candidate block does not belong to a codingtree unit the same as that of the current block, a merge candidate maybe derived using a block belonging to the same coding tree unit as thecurrent block or a block including a reference sample adjacent to theboundary of the coding tree unit, instead of the candidate block.

FIG. 15 is a view showing an example in which the position of areference sample is changed.

When a reference sample is included in a coding tree unit different fromthe current block, and the reference sample is not adjacent to theboundary of the coding tree unit, a candidate block may be determinedusing a reference sample adjacent to the boundary of the coding treeunit, instead of the reference sample.

For example, in the examples shown in FIGS. 15 (a) and 15 (b), when thetop boundary of the current block and the top boundary of the codingtree unit are in contact with each other, the reference samples on thetop of the current block belong to a coding tree unit different from thecurrent block. Among the reference samples belonging to the coding treeunit different from the current block, a reference sample not adjacentto the top boundary of the coding tree unit may be replaced with asample adjacent to the top boundary of the coding tree unit.

For example, as shown in the example of FIG. 15 (a), the referencesample at position 6 is replaced with the sample at position 6′positioned at the top boundary of the coding tree unit, and as shown inthe example of FIG. 15 (b), the reference sample at position 15 isreplaced with the sample at position 15′ positioned at the top boundaryof the coding tree unit. At this point, the y coordinate of thereplacement sample is changed to a position adjacent to the coding treeunit, and the x coordinate of the replacement sample may be set to beequal to the reference sample. For example, the sample at position 6′may have the same x-coordinate as the sample at position 6, and thesample at position 15′ may have the same x-coordinate as the sample atposition 15.

Alternatively, a value obtained by adding or subtracting an offset to orfrom the x coordinate of the reference sample may be set as the xcoordinate of the replacement sample. For example, when thex-coordinates of the neighboring reference sample positioned on the topof the current block and the non-neighboring reference sample are thesame, a value obtained by adding or subtracting an offset to or from thex coordinate of the reference sample may be set as the x coordinate ofthe replacement sample. This is for preventing the replacement samplereplacing the non-neighboring reference sample from being placed at thesame position as another non-neighboring reference sample or neighboringreference sample.

FIG. 16 is a view showing an example in which the position of areference sample is changed.

In replacing a reference sample that is included in a coding tree unitdifferent from the current block and is not adjacent to the boundary ofthe coding tree unit with a sample positioned at the boundary of thecoding tree unit, a value obtained by adding or subtracting an offset toand from the x coordinate of the reference sample may be set as thex-coordinate of the replacement sample.

For example, in the example shown in FIG. 16 , the reference sample atposition 6 and the reference sample at position 15 may be replaced withthe sample at position 6′ and the sample at position 15′ respectively,of which the y coordinates are the same as that of the row adjacent tothe top boundary of the coding tree unit. At this point, thex-coordinate of the sample at position 6′ may be set to a value obtainedby subtracting W/2 from the x-coordinate of the reference sample atposition 6, and the x-coordinate of the sample at position 15′ may beset to a value obtained by subtracting W−1 from the x-coordinate of thereference sample at position 15.

Unlike the examples shown in FIGS. 15 and 16 , the y coordinate of therow positioned on the top of the uppermost row of the current block orthe y coordinate of the top boundary of the coding tree unit may be setas the y coordinate of the replacement sample.

Although not shown, a sample replacing the reference sample may bedetermined based on the left-side boundary of the coding tree unit. Forexample, when the reference sample is not included in the same codingtree unit as the current block and is not adjacent to the left-sideboundary of the coding tree unit, the reference sample may be replacedwith a sample adjacent to the left-side boundary of the coding treeunit. At this point, the replacement sample may have a y-coordinate thesame as that of the reference sample, or may have a y-coordinateobtained by adding or subtracting an offset to and from the y-coordinateof the reference sample.

Thereafter, a block including the replacement sample may be set as acandidate block, and a merge candidate of the current block may bederived based on the candidate block.

A merge candidate may also be derived from a temporally neighboringblock included in a picture different from the current block. Forexample, a merge candidate may be derived from a collocated blockincluded in a collocated picture.

The motion information of the merge candidate may be set to be equal tothe motion information of the candidate block. For example, at least oneamong a motion vector, a reference picture index, a predictiondirection, and a bidirectional weight index of the candidate block maybe set as motion information of the merge candidate.

A merge candidate list including merge candidates may be generated(S1102). The merge candidates may be divided into a neighboring mergecandidate derived from a neighboring block adjacent to the current blockand a non-adjacent merge candidate derived from a non-neighboring block.

Indexes of the merge candidates in the merge candidate list may beassigned in a predetermined order. For example, an index assigned to anadjacent merge candidate may have a value smaller than an index assignedto a non-adjacent merge candidate. Alternatively, an index may beassigned to each of the merge candidates based on the index of eachblock shown in FIG. 12 or 14 .

When a plurality of merge candidates is included in the merge candidatelist, at least one among the plurality of merge candidates may beselected (S1103). At this point, information indicating whether motioninformation of the current block is derived from an adjacent mergecandidate may be signaled through a bitstream. The information may be a1-bit flag. For example, a syntax element isAdjancentMergeFlagindicating whether the motion information of the current block isderived from an adjacent merge candidate may be signaled through abitstream. When the value of the syntax element isAdjancentMergeFlag is1, motion information of the current block may be derived based on theadjacent merge candidate. Contrarily, when the value of the syntaxelement isAdjancentMergeFlag is 0, motion information of the currentblock may be derived based on a non-adjacent merge candidate.

Table 1 shows a syntax table including syntax elementisAdjancentMergeFlag.

TABLE 1 Descriptor coding_unit( x0, y0, cbWidth, cbHeight, treeType ) { if( slice_type != I ) {   pred_mode_flag ae(v)  }  if( CuPredMode[ x0][ y0] = = MODE_INTRA ) {  if( treeType = = SINGLE_TREE ∥ treeType = =DUAL_TREE_LUMA ) {   intra_luma_mpm_flag[ x0 ][ y0 ]   if(intra_luma_mpm_flag[ x0 ][ y0 ] )   intra_luma_mpm_idx[ x0 ][ y0 ] ae(v)  else   intra_luma_mpm_remainder[ x0 ][ y0 ] ae(v)  }  if( treeType = =SINGLE_TREE ∥ treeType = = DUAL_TREE_CHROMA )   intra_chroma_pred_mode[x0 ][ y0 ] ae(v)  } else {  if (cu_skip_falg[x0][y0]) {   if(MaxNumMergeCand > 1){   isAdjacentMergeflag ae(v)   if(isAdjcanetMergeflag){   merge_idx[x0][y0] ae(v)   } else{  NA_merge_idx[x0][y0] ae(v)   }  }  } else { /* MODE_INTER*/ merge_flag[x0][y0] ae(v)  if (merge_flag[x0][y0]){   if(MaxNumMergeCand > 1){   isAdjacentMergeflag ae(v)   if(isAdjcanetMergeflag){   merge_idx[x0][y0] ae(v)   } else{  NA_merge_idx[x0][y0] ae(v)   }  }  }  if( CuPredMode[ x0 ][ y0 ] !=MODE_INTRA )  cu_cbf ae(v)  if( cu_cbf ) {  transform_tree( x0, y0,cbWidth, cbHeight, treeType )

Information for specifying any one among a plurality of merge candidatesmay be signaled through a bitstream. For example, information indicatingan index of any one among the merge candidates included in the mergecandidate list may be signaled through a bitstream.

When isAdjacentMergeflag is 1, syntax element merge_idx specifying anyone among the adjacent merge candidates may be signaled. The maximumvalue of syntax element merge_idx may be set to a value obtained bysubtracting 1 from the number of adjacent merge candidates.

When isAdjacentMergeflag is 0, syntax element NA_merge_idx specifyingany one among the non-adjacent merge candidates may be signaled. Thesyntax element NA_merge_idx represents a value obtained by subtractingthe number of adjacent merge candidates from the index of thenon-adjacent merge candidate. The decoder may select a non-adjacentmerge candidate by adding the number of adjacent merge candidates to anindex specified by NA_merge_idx.

When the number of merge candidates included in the merge candidate listis smaller than a threshold value, the merge candidate included in theinter-region motion information list may be added to the merge candidatelist. Here, the threshold value may be the maximum number of mergecandidates that can be included in the merge candidate list or a valueobtained by subtracting an offset from the maximum number of mergecandidates. The offset may be a natural number such as 1, 2 or the like.The inter-region motion information list may include a merge candidatederived based on a block encoded/decoded before the current block.

The inter-region motion information list includes a merge candidatederived from a block encoded/decoded based on inter prediction in thecurrent picture. For example, motion information of a merge candidateincluded in the inter-region motion information list may be set to beequal to motion information of a block encoded/decoded based on interprediction. Here, the motion information may include at least one amonga motion vector, a reference picture index, a prediction direction, anda bidirectional weight index.

For convenience of explanation, a merge candidate included in theinter-region motion information list will be referred to as aninter-region merge candidate.

The maximum number of merge candidates that can be included in theinter-region motion information list may be predefined by an encoder anda decoder. For example, the maximum number of merge candidates that canbe included in the inter-region motion information list may be 1, 2, 3,4, 5, 6, 7, 8 or more (e.g., 16).

Alternatively, information indicating the maximum number of mergecandidates in the inter-region motion information list may be signaledthrough a bitstream. The information may be signaled at the sequence,picture, or slice level.

Alternatively, the maximum number of merge candidates of theinter-region motion information list may be determined according to thesize of a picture, the size of a slice, or the size of a coding treeunit.

The inter-region motion information list may be initialized by the unitof picture, slice, tile, brick, coding tree unit, or coding tree unitline (row or column). For example, when a slice is initialized, theinter-region motion information list is also initialized, and theinter-region motion information list may not include any mergecandidate.

Alternatively, information indicating whether or not to initialize theinter-region motion information list may be signaled through abitstream. The information may be signaled at the slice, tile, brick, orblock level. Until the information indicates to initialize theinter-region motion information list, a previously configuredinter-region motion information list may be used.

Alternatively, information on the initial inter-region merge candidatemay be signaled through a picture parameter set or a slice header.Although the slice is initialized, the inter-region motion informationlist may include the initial inter-region merge candidate. Accordingly,an inter-region merge candidate may be used for a block that is thefirst encoding/decoding target in the slice.

Blocks are encoded/decoded according to an encoding/decoding order, andblocks encoded/decoded based on inter prediction may be sequentially setas an inter-region merge candidate according to an encoding/decodingorder.

FIG. 17 is a flowchart illustrating a process of updating aninter-region motion information list.

When inter prediction is performed on the current block (S1701), aninter-region merge candidate may be derived based on the current block(S1702). Motion information of the inter-region merge candidate may beset to be equal to the motion information of the current block.

When the inter-region motion information list is empty (S1703), theinter-region merge candidate derived based on the current block may beadded to the inter-region motion information list (S1704).

When the inter-region motion information list already includes theinter-region merge candidate (S1703), a redundancy check may beperformed on the motion information of the current block (or theinter-region merge candidate derived based on the current block)(S1705). The redundancy check is for determining whether motioninformation of an inter-region merge candidate previously stored in theinter-region motion information list and motion information of thecurrent block are the same. The redundancy check may be performed on allinter-region merge candidates previously stored in the inter-regionmotion information list. Alternatively, the redundancy check may beperformed on inter-region merge candidates having an index larger thanor equal to a threshold value among inter-region merge candidatespreviously stored in the inter-region motion information list.

When an inter-region merge candidate having the same motion informationas the motion information of the current block is not included, theinter-region merge candidate derived based on the current block may beadded to the inter-region motion information list (S1708). Whether theinter-region merge candidates are the same may be determined based onwhether motion information (e.g., a motion vector and/or a referencepicture index) of the inter-region merge candidates is the same.

At this point, when the maximum number of inter-region merge candidatesare already stored in the inter-region motion information list (S1706),the oldest inter-region merge candidate is deleted (S1707), and theinter-region merge candidate derived based on the current block may beadded to the inter-region motion information list (S1708).

Each of the inter-region merge candidates may be identified by an index.When an inter-region merge candidate derived from the current block isadded to the inter-region motion information list, the lowest index(e.g., 0) is assigned to the inter-region merge candidate, and indexesof previously stored inter-region merge candidates may be increasedby 1. At this point, when the maximum number of inter-region mergecandidates are already stored in the inter-region motion informationlist, an inter-region merge candidate having the largest index isremoved.

Alternatively, when the inter-region merge candidate derived from thecurrent block is added to the inter-region motion information list, thelargest index may be assigned to the inter-region merge candidate. Forexample, when the number of inter-region merge candidates previouslystored in the inter-region motion information list is smaller than amaximum value, an index having the same value as the number ofpreviously stored inter-region merge candidates may be assigned to theinter-region merge candidate. Alternatively, when the number ofinter-region merge candidates previously stored in the inter-regionmotion information list is the same as the maximum value, an indexsubtracting 1 from the maximum value may be assigned to the inter-regionmerge candidate. In addition, an inter-region merge candidate having thesmallest index is removed, and indexes of remaining previously storedinter-region merge candidates may be decreased by 1.

FIG. 18 is a view showing an embodiment of updating an inter-regionmerge candidate list.

It is assumed that as the inter-region merge candidate derived from thecurrent block is added to the inter-region merge candidate list, thelargest index is assigned to the inter-region merge candidate. Inaddition, it is assumed that the maximum number of inter-region mergecandidates are already stored in the inter-region merge candidate list.

When the inter-region merge candidate HmvpCand[n+1] derived from thecurrent block is added to the inter-region merge candidate listHmvpCandList, the inter-region merge candidate HmvpCand[0] having thesmallest index among the previously stored inter-region merge candidatesis deleted, and the indexes of the remaining inter-region mergecandidates may be decreased by 1. In addition, the index of theinter-region merge candidate HmvpCand[n+1] derived from the currentblock may be set to a maximum value (n in the example shown in FIG. 18).

When an inter-region merge candidate the same as the inter-region mergecandidate derived based on the current block is previously stored(S1705), the inter-region merge candidate derived based on the currentblock may not be added to the inter-region motion information list(S1709).

Alternatively, as the inter-region merge candidate derived based on thecurrent block is added to the inter-region motion information list, apreviously stored inter-region merge candidate that is the same as theinter-region merge candidate may be removed. In this case, an effect thesame as newly updating the index of the previously stored inter-regionmerge candidate is obtained.

FIG. 19 is a view showing an example in which an index of a previouslystored inter-region merge candidate is updated.

When the index of a previously stored inter-region merge candidatemvCand that is the same as the inter-region merge candidate mvCandderived based on the current block is hIdx, the previously storedinter-region merge candidate is deleted, and indexes of inter-regionmerge candidates having an index larger than hIdx may be decreased by 1.For example, in the example shown in FIG. 19 , it is shown thatHmvpCand[2] the same as mvCand is deleted from the inter-region motioninformation list HvmpCandList, and the indexes of HmvpCand[3] toHmvpCand[n] are decreased by 1.

In addition, the inter-region merge candidate mvCand derived based onthe current block may be added to the end of the inter-region motioninformation list.

Alternatively, the index assigned to the previously stored inter-regionmerge candidate that is the same as the inter-region merge candidatederived based on the current block may be updated. For example, theindex of the previously stored inter-region merge candidate may bechanged to a minimum value or a maximum value.

It may be set not to add motion information of blocks included in apredetermined area to the inter-region motion information list. Forexample, an inter-region merge candidate derived based on motioninformation of a block included in the merge processing area may not beadded to the inter-region motion information list. Since anencoding/decoding order is not defined for the blocks included in themerge processing area, it is inappropriate to use motion information ofany one among the blocks for inter prediction of another block.Accordingly, inter-region merge candidates derived based on the blocksincluded in the merge processing area may not be added to theinter-region motion information list.

When motion compensation prediction is performed by the unit ofsubblock, an inter-region merge candidate may be derived based on motioninformation of a representative subblock among a plurality of subblocksincluded in the current block. For example, when a subblock mergecandidate is used for the current block, an inter-region merge candidatemay be derived based on motion information of a representative subblockamong the subblocks.

Motion vectors of the subblocks may be derived in the following order.First, any one among the merge candidates included in the mergecandidate list of the current block is selected, and an initial shiftvector (shVector) may be derived based on the motion vector of theselected merge candidate. Then, a shifted subblock, in which theposition of the reference sample is (xColSb, yColSb), may be derived asthe initial shift vector is added at the position (xSb, ySb) of thereference sample (e.g., the top-left sample or the sample at the center)of each subblock in the coding block. Equation 4 shows an equation forderiving the shifted subblock.(xColSb,yColSb)=(xSb+shVector[0]>>4,ySb+shVector[1]>>4)  [Equation 4]

Then, the motion vector of a collocated block corresponding to thecenter position of the subblock including (xColSb, yColSb) may be set asthe motion vector of the subblock including (xSb, ySb).

The representative subblock may mean a subblock including the top-leftsample or the sample at the center of the current block.

FIG. 20 is a view showing the position of a representative subblock.

FIG. 20 (a) shows an example in which the subblock positioned at thetop-left of the current block is set as the representative subblock, andFIG. 20 (b) shows an example in which the subblock positioned at thecenter of the current block is set as the representative subblock. Whenmotion compensation prediction is performed by unit of subblock, aninter-region merge candidate of the current block may be derived basedon the motion vector of the subblock including the top-left sample ofthe current block or the subblock including the sample at the center ofthe current block.

It may be determined whether or not to use the current block as aninter-region merge candidate, based on the inter prediction mode of thecurrent block. For example, a block encoded/decoded based on an affinemotion model may be set to be unavailable as an inter-region mergecandidate. Accordingly, although the current block is encoded/decoded byinter prediction, when the inter prediction mode of the current block isthe affine prediction mode, the inter-region motion information list maynot be updated based on the current block.

Alternatively, the inter-region merge candidate may be derived based onat least one subblock vector among the subblocks included in the blockencoded/decoded based on the affine motion model. For example, theinter-region merge candidate may be derived using a subblock positionedat the top-left, a subblock positioned at the center, or a subblockpositioned at the top-right side of the current block. Alternatively, anaverage value of subblock vectors of a plurality of subblocks may be setas the motion vector of the inter-region merge candidate.

Alternatively, the inter-region merge candidate may be derived based onan average value of affine seed vectors of the block encoded/decodedbased on the affine motion model. For example, an average of at leastone among the first affine seed vector, the second affine seed vector,and the third affine seed vector of the current block may be set as themotion vector of the inter-region merge candidate.

Alternatively, an inter-region motion information list may be configuredfor each inter prediction mode. For example, at least one among aninter-region motion information list for a block encoded/decoded byintra-block copy, an inter-region motion information list for a blockencoded/decoded based on a translational motion model, and aninter-region motion information list for a block encoded/decoded basedon an affine motion model may be defined. According to the interprediction mode of the current block, any one among a plurality ofinter-region motion information lists may be selected.

FIG. 21 is a view showing an example in which an inter-region motioninformation list is generated for each inter prediction mode.

When a block is encoded/decoded based on a non-affine motion model, aninter-region merge candidate mvCand derived based on the block may beadded to an inter-region non-affine motion information listHmvpCandList. Contrarily, when a block is encoded/decoded based on anaffine motion model, an inter-region merge candidate mvAfCand derivedbased on the block may be added to an inter-region affine motioninformation list HmvpAfCandList.

Affine seed vectors of a block encoded/decoded based on the affinemotion model may be stored in an inter-region merge candidate derivedfrom the block. Accordingly, the inter-region merge candidate may beused as a merge candidate for deriving the affine seed vector of thecurrent block.

In addition to the inter-region motion information list described above,an additional inter-region motion information list may be defined. Inaddition to the inter-region motion information list described above(hereinafter, referred to as a first inter-region motion informationlist), a long-term motion information list (hereinafter, referred to asa second inter-region motion information list) may be defined. Here, thelong-term motion information list includes long-term merge candidates.

When both the first inter-region motion information list and the secondinter-region motion information list are empty, first, an inter-regionmerge candidate may be added to the second inter-region motioninformation list. Only after the number of available inter-region mergecandidates reaches the maximum number in the second inter-region motioninformation list, an inter-region merge candidate may be added to thefirst inter-region motion information list.

Alternatively, one inter-region merge candidate may be added to both thesecond inter-region motion information list and the first inter-regionmotion information list.

At this point, the second inter-region motion information list, theconfiguration of which has been completed, may not be updated any more.Alternatively, when the decoded region is greater than or equal to apredetermined ratio of the slice, the second inter-region motioninformation list may be updated. Alternatively, the second inter-regionmotion information list may be updated for every N coding tree unitlines.

Contrarily, the first inter-region motion information list may beupdated whenever a block encoded/decoded by inter prediction isgenerated. However, it may be set not to use the inter-region mergecandidate added to the second inter-region motion information list, toupdate the first inter-region motion information list.

Information for selecting any one among the first inter-region motioninformation list and the second inter-region motion information list maybe signaled through a bitstream. When the number of merge candidatesincluded in the merge candidate list is smaller than a threshold value,merge candidates included in the inter-region motion information listindicated by the information may be added to the merge candidate list.

Alternatively, an inter-region motion information list may be selectedbased on the size and shape of the current block, inter prediction mode,whether bidirectional prediction is enabled, whether motion vectorrefinement is enabled, or whether triangular partitioning is enabled.

Alternatively, although an inter-region merge candidate included in thefirst inter-region motion information list is added, when the number ofmerge candidates included in the merge candidate list is smaller thanthe maximum number of merges, the inter-region merge candidates includedin the second inter-region motion information list may be added to themerge candidate list.

FIG. 22 is a view showing an example in which an inter-region mergecandidate included in a long-term motion information list is added to amerge candidate list.

When the number of merge candidates included in the merge candidate listis smaller than the maximum number, the inter-region merge candidatesincluded in the first inter-region motion information list HmvpCandListmay be added to the merge candidate list. When the number of mergecandidates included in the merge candidate list is smaller than themaximum number although the inter-region merge candidates included inthe first inter-region motion information list are added to the mergecandidate list, inter-region merge candidates included in the long-termmotion information list HmvpLTCandList may be added to the mergecandidate list.

Table 2 shows a process of adding inter-region merge candidates includedin the long-term motion information list to the merge candidate list.

TABLE 2 For each candidate in HMVPCandList with index HMVPLTIdx = 1 ..numHMVPLTCand, the following ordered steps are repeated until combStopis equal to true  sameMotion is set to FALSE  If hmvpStop is equal toFALSE and numCurrMergecand is less than (MaxNumMergeCand-1), hmvpLT isset to TRUE  If HMVPLTCandList[NumLTHmvp-HMVPLTIdx] have the same motionvectors and the same reference indices with any mergeCandList[i] with Ibeing 0.. numOrigMergeCand-1 and HasBeenPruned[i] equal to false,sameMotion is set to true  If sameMotion is equal to false,mergeCandList[numCurrMergeCand++] is set toHMVPLTCandList[NumLTHmvp-HMVPLTIdx]  If numCurrMergeCand is equal to(MaxNumMergeCand-1), hmvpLTStop is set to TRUE

The inter-region merge candidate may be set to include additionalinformation, in addition to motion information. For example, for theinter-region merge candidate, a size, a shape, or partition informationof a block may be additionally stored. When the merge candidate list ofthe current block is constructed, only inter-region merge candidateshaving a size, a shape, or partition information the same as or similarto those of the current block are used among the inter-region mergecandidates, or inter-region merge candidates having a size, a shape, orpartition information the same as or similar to those of the currentblock may be added to the merge candidate list in the first place.

Alternatively, an inter-region motion information list may be generatedfor each of the size, shape, or partition information of a block. Amongthe plurality of inter-region motion information lists, a mergecandidate list of the current block may be generated by using aninter-region motion information list corresponding to the shape, size,or partition information of the current block.

When the number of merge candidates included in the merge candidate listof the current block is smaller than the threshold value, theinter-region merge candidates included in the inter-region motioninformation list may be added to the merge candidate list. The additionprocess is performed in an ascending or descending order based on theindex. For example, an inter-region merge candidate having the largestindex may be first added to the merge candidate list.

When it is desired to add an inter-region merge candidate included inthe inter-region motion information list to the merge candidate list, aredundancy check may be performed between the inter-region mergecandidate and the merge candidates previously stored in the mergecandidate list.

For example, Table 3 shows a process in which an inter-region mergecandidate is added to the merge candidate list.

TABLE 3 For each candidate in HMVPCandList with index HMVPIdx = 1..numCheckedHMVPCand, the following ordered steps are repeated untilcombStop is equal to true  sameMotion is set to false  IfHMVPCandList[NumHmvp-HMVPIdx] have the same motion vectors and the samereference indices with any mergeCandList[i] with I being 0..numOrigMergeCand-1 and HasBeenPruned[i] equal to false, sameMotion isset to true  If sameMotion is equal to false,mergeCandList[numCurrMergeCand++] is set toHMVPCandList[NumHmvp-HMVPIdx]  If numCurrMergeCand is equal to(MaxNumMergeCand-1), hmvpStop is set to TRUE

The redundancy check may be performed only on some of the inter-regionmerge candidates included in the inter-region motion information list.For example, the redundancy check may be performed only on inter-regionmerge candidates having an index larger than a threshold value orsmaller than a threshold value. Alternatively, the redundancy check maybe performed only on N merge candidates having the largest index or Nmerge candidates having the smallest index.

Alternatively, the redundancy check may be performed only on some of themerge candidates previously stored in the merge candidate list. Forexample, the redundancy check may be performed only on a merge candidatehaving an index larger than a threshold value or smaller than athreshold value, or on a merge candidate derived from a block at aspecific position. Here, the specific position may include at least oneamong a left neighboring block, a top neighboring block, a top-rightneighboring block, and a bottom-left neighboring block of the currentblock.

FIG. 23 is a view showing an example in which a redundancy check isperformed only on some of merge candidates.

When it is desired to add the inter-region merge candidate HmvpCand[j]to the merge candidate list, a redundancy check may be performed on theinter-region merge candidate with two merge candidatesmergeCandList[NumMerge-2] and mergeCandList[NumMerge-1] having thelargest indexes. Here, NumMerge may represent the number of spatialmerge candidates and temporal merge candidates that are available.

Unlike the example shown in the drawing, when it is desired to add aninter-region merge candidate HmvpCand[j] to the merge candidate list, aredundancy check may be performed on the inter-region merge candidatewith up to two merge candidates having the smallest index. For example,it is possible to check whether mergeCandList[0] and mergeCandList[1]are the same as HmvpCand[j]. Alternatively, a redundancy check may beperformed only on merge candidates derived at a specific position. Forexample, the redundancy check may be performed on at least one among amerge candidate derived from a neighboring block positioned on the leftside of the current block and a merge candidate derived from aneighboring block positioned on the top the current block. When a mergecandidate derived at a specific position does not exist in the mergecandidate list, an inter-region merge candidate may be added to themerge candidate list without having a redundancy check.

When a merge candidate the same as the first inter-region mergecandidate is found and a redundancy check is performed on the secondinter-region merge candidate, the redundancy check with the mergecandidate the same as the first inter-region merge candidate may beomitted.

FIG. 24 is a view showing an example in which a redundancy check isomitted for a specific merge candidate.

When it is desired to add an inter-region merge candidate HmvpCand[i]having index i to the merge candidate list, a redundancy check isperformed between the inter-region merge candidate and merge candidatespreviously stored in the merge candidate list. At this point, when amerge candidate mergeCandList[j] the same as the inter-region mergecandidate HmvpCand[i] is found, the redundancy check may be performedbetween the inter-region merge candidate HmvpCand[i−1] having index i−1and the merge candidates without adding the inter-region merge candidateHmvpCand[i] to the merge candidate list. At this point, the redundancycheck between the inter-region merge candidate HmvpCand[i−1] and themerge candidate mergeCandList[j] may be omitted.

For example, in the example shown in FIG. 24 , it is determined thatHmvpCand[i] and mergeCandList[2] are the same. Accordingly, HmvpCand[i]is not added to the merge candidate list, and a redundancy check may beperformed on HmvpCand[i−1]. At this point, the redundancy check betweenHvmpCand[i−1] and mergeCandList[2] may be omitted.

When the number of merge candidates included in the merge candidate listof the current block is smaller than the threshold value, at least oneamong a pairwise merge candidate and a zero-merge candidate may befurther included, in addition to the inter-region merge candidate. Thepairwise merge candidate means a merge candidate having an average valueof motion vectors of two or more merge candidates as a motion vector,and the zero-merge candidate means a merge candidate having a motionvector of 0.

A merge candidate may be added to the merge candidate list of thecurrent block in the following order.

Spatial merge candidate—Temporal merge candidate—Inter-region mergecandidate—(Inter-region affine merge candidate)—Pairwise mergecandidate—Zero-merge candidate

The spatial merge candidate means a merge candidate derived from atleast one among a neighboring block and a non-neighboring block, and thetemporal merge candidate means a merge candidate derived from a previousreference picture. The inter-region affine merge candidate represents aninter-region merge candidate derived from a block encoded/decoded withan affine motion model.

The inter-region motion information list may also be used in the motionvector prediction mode. For example, when the number of motion vectorprediction candidates included in a motion vector prediction candidatelist of the current block is smaller than a threshold value, aninter-region merge candidate included in the inter-region motioninformation list may be set as a motion vector prediction candidate forthe current block. Specifically, the motion vector of the inter-regionmerge candidate may be set as a motion vector prediction candidate.

When any one among the motion vector prediction candidates included inthe motion vector prediction candidate list of the current block isselected, the selected candidate may be set as the motion vectorpredictor of the current block. Thereafter, after a motion vectorresidual coefficient of the current block is decoded, a motion vector ofthe current block may be obtained by adding the motion vector predictorand the motion vector residual coefficient.

The motion vector prediction candidate list of the current block may beconfigured in the following order.

Spatial motion vector prediction candidate—Temporal motion vectorprediction candidate—Inter-region merge candidate—(Inter-region affinemerge candidate)—Zero-motion vector prediction candidate

The spatial motion vector prediction candidate means a motion vectorprediction candidate derived from at least one among a neighboring blockand a non-neighboring block, and the temporal motion vector predictioncandidate means a motion vector prediction candidate derived from aprevious reference picture. The inter-region affine merge candidaterepresents an inter-region motion vector prediction candidate derivedfrom a block encoded/decoded with the affine motion model. Thezero-motion vector prediction candidate represents a candidate having amotion vector value of 0.

A merge processing area having a size greater than that of a codingblock may be defined. Coding blocks included in the merge processingarea are not sequentially encoded/decoded, and may be processed inparallel. Here, that coding blocks are not sequentially encoded/decodedmeans that an encoding/decoding order is not defined. Accordingly, aprocess of encoding/decoding the blocks included in the merge processingarea may be independently processed. Alternatively, the blocks includedin the merge processing area may share merge candidates. Here, the mergecandidates may be derived based on the merge processing area.

According to the characteristics described above, the merge processingarea may also be referred to as a parallel processing area, a sharedmerge area (SMR), or a merge estimation area (MER).

The merge candidate of the current block may be derived based on thecoding block. However, when the current block is included in a mergeprocessing area of a size greater than the current block, a candidateblock included in the merge processing area the same as the currentblock may be set to be unavailable as a merge candidate.

FIG. 25 is a view showing an example in which candidate blocks includedin the same merge processing area as the current block are set to beunavailable as a merge candidate.

In the example shown in FIG. 25 (a), when CU5 is encoded/decoded, blocksincluding reference samples adjacent to CU5 may be set as candidateblocks. At this point, candidate blocks X3 and X4 included in the mergeprocessing area the same as CU5 may be set to be unavailable as a mergecandidate of CU5. Contrarily, candidate blocks X0, X1 and X2 that arenot included in the merge processing area the same as CU5 may be set tobe available as a merge candidate.

In the example shown in FIG. 25 (b), when CU8 is encoded/decoded, blocksincluding reference samples adjacent to CU8 may be set as candidateblocks. At this point, candidate blocks X6, X7 and X8 included in themerge processing area the same as CU8 may be set to be unavailable as amerge candidate. Contrarily, candidate blocks X5 and X9 that are notincluded in the merge processing area the same as CU8 may be set to beavailable as a merge candidate.

The merge processing area may be a square or non-square shape.Information for determining the merge processing area may be signaledthrough a bitstream. The information may include at least one amonginformation indicating the shape of the merge processing area andinformation indicating the size of the merge processing area. When themerge processing area is a non-square shape, at least one amonginformation indicating the size of the merge processing area,information indicating the width and/or height of the merge processingarea, and information indicating a ratio of width to height of the mergeprocessing area may be signaled through a bitstream.

The size of the merge processing area may be determined based on atleast one among information signaled through a bitstream, a pictureresolution, a slice size, and a tile size.

When motion compensation prediction is performed on a block included inthe merge processing area, an inter-region merge candidate derived basedon motion information of the block on which motion compensationprediction has been performed may be added to the inter-region motioninformation list.

However, in the case where an inter-region merge candidate derived froma block included in the merge processing area is added to theinter-region motion information list, when another block in the mergeprocessing area, which actually is encoded/decoded after the block isencoded/decoded, is encoded/decoded, there may be a case of using aninter-region merge candidate derived from the block. That is, althoughdependency among blocks should be excluded when the blocks included inthe merge processing area are encoded/decoded, there may be a case acase of performing motion prediction compensation using motioninformation of another block included in the merge processing area. Inorder to solve the problem, although encoding/decoding of a blockincluded in the merge processing area is completed, motion informationof the encoded/decoded block may not be added to the inter-region motioninformation list.

Alternatively, when motion compensation prediction is performed on theblocks included in the merge processing area, inter-region mergecandidates derived from the blocks may be added to the inter-regionmotion information list in a predefined order. Here, the predefinedorder may be determined according to the scan order of the coding blocksin the merge processing area or the coding tree unit. The scan order maybe at least one among the raster scan, horizontal scan, vertical scan,and zigzag scan. Alternatively, the predefined order may be determinedbased on motion information of each block or the number of blocks havingthe same motion information.

Alternatively, an inter-region merge candidate including unidirectionalmotion information may be added to the inter-region merge list before aninter-region merge candidate including bidirectional motion information.Contrarily, an inter-region merge candidate including bidirectionalmotion information may be added to the inter-region merge candidate listbefore an inter-region merge candidate including unidirectional motioninformation.

Alternatively, an inter-region merge candidate may be added to theinter-region motion information list according to an order of a high usefrequency or a low use frequency within the merge processing area or thecoding tree unit.

When the current block is included in the merge processing area and thenumber of merge candidates included in the merge candidate list of thecurrent block is smaller than the maximum number, inter-region mergecandidates included in the inter-region motion information list may beadded to the merge candidate list. At this point, it may be set not toadd an inter-region merge candidate derived from a block included in amerge processing area the same as the current block to the mergecandidate list of the current block.

Alternatively, when the current block is included in the mergeprocessing area, it may be set not to use the inter-region mergecandidates included in the inter-region motion information list. Thatis, although the number of merge candidates included in the mergecandidate list of the current block is smaller than the maximum number,the inter-region merge candidates included in the inter-region motioninformation list may not be added to the merge candidate list.

An inter-region motion information list for a merge processing area or acoding tree unit may be configured. This inter-region motion informationlist performs a function of temporarily storing motion information ofblocks included in the merge processing area. In order to distinguish ageneral inter-region motion information list from the inter-regionmotion information list for a merge processing area or a coding treeunit, the inter-region motion information list for a merge processingarea or a coding tree unit is referred to as a temporary motioninformation list. In addition, an inter-region merge candidate stored inthe temporary motion information list will be referred to as a temporarymerge candidate.

FIG. 26 is a view showing a temporary motion information list.

A temporary motion information list for a coding tree unit or a mergeprocessing area may be configured. When motion compensation predictionhas been performed on the current block included in the coding tree unitor the merge processing area, motion information of the block may not beadded to the inter-region motion information list HmvpCandList. Instead,a temporary merge candidate derived from the block may be added to thetemporary motion information list HmvpMERCandList. That is, thetemporary merge candidate added to the temporary motion information listmay not be added to the inter-region motion information list.Accordingly, the inter-region motion information list may not includeinter-region merge candidates derived based on motion information of theblocks included in the coding tree unit or the merge processing area.

The maximum number of merge candidates that the temporary motioninformation list may include may be set to be the same as that of theinter-region motion information list. Alternatively, the maximum numberof merge candidates that the temporary motion information list mayinclude may be determined according to the size of the coding tree unitor the merge processing area.

The current block included in the coding tree unit or the mergeprocessing area may be set not to use the temporary motion informationlist for a corresponding coding tree unit or a corresponding mergeprocessing area. That is, when the number of merge candidates includedin the merge candidate list of the current block is smaller than athreshold value, the inter-region merge candidates included in theinter-region motion information list are added to the merge candidatelist, and the temporary merge candidates included in the temporarymotion information list may not be added to the merge candidate list.Accordingly, motion information of other blocks included in the codingtree unit or the merge processing area the same as the current block maynot be used for motion compensation prediction of the current block.

When encoding/decoding of all the blocks included in the coding treeunit or the merge processing area is completed, the inter-region motioninformation list and the temporary motion information list may bemerged.

FIG. 27 is a view showing an example of merging an inter-region motioninformation list and a temporary motion information list.

When coding/decoding of all the blocks included in the coding tree unitor the merge processing area is completed, as shown in the example ofFIG. 27 , the inter-region motion information list may be updated withthe temporary merge candidates included in the temporary motioninformation list.

At this point, the temporary merge candidates included in the temporarymotion information list may be added to the inter-region motioninformation list in order of the temporary merge candidates inserted inthe temporary motion information list (i.e., in ascending or descendingorder of index values).

As another example, the temporary merge candidates included in thetemporary motion information list may be added to the inter-regionmotion information list in a predefined order.

Here, the predefined order may be determined according to the scan orderof the coding blocks in the merge processing area or the coding treeunit. The scan order may be at least one among the raster scan,horizontal scan, vertical scan, and zigzag scan. Alternatively, thepredefined order may be determined based on motion information of eachblock or the number of blocks having the same motion information.

Alternatively, a temporary merge candidate including unidirectionalmotion information may be added to the inter-region merge list before atemporary merge candidate including bidirectional motion information.Contrarily, a temporary merge candidate including bidirectional motioninformation may be added to the inter-region merge candidate list beforea temporary merge candidate including unidirectional motion information.

Alternatively, a temporary merge candidate may be added to theinter-region motion information list according to an order of a high usefrequency or a low use frequency within the merge processing area or thecoding tree unit.

When a temporary merge candidate included in the temporary motioninformation list is added to the inter-region motion information list, aredundancy check may be performed on the temporary merge candidate. Forexample, when an inter-region merge candidate the same as the temporarymerge candidate included in the temporary motion information list ispreviously stored in the inter-region motion information list, thetemporary merge candidate may not be added to the inter-region motioninformation list. At this point, a redundancy check may be performed onsome of the inter-region merge candidates included in the inter-regionmotion information list. For example, the redundancy check may beperformed on inter-region merge candidates having an index larger than athreshold value or smaller than a threshold value. For example, when thetemporary merge candidate is the same as an inter-region merge candidatehaving an index larger than or equal to a predefined value, thetemporary merge candidate may not be added to the inter-region motioninformation list.

Intra prediction is for predicting a current block using reconstructedsamples that have been encoded/decoded in the neighborhood of thecurrent block. At this point, samples reconstructed before an in-loopfilter is applied may be used for intra prediction of the current block.

The intra prediction technique includes matrix-based intra prediction,and general intra prediction considering directionality with respect toneighboring reconstructed samples. Information indicating the intraprediction technique of the current block may be signaled through abitstream. The information may be a 1-bit flag. Alternatively, the intraprediction technique of the current block may be determined based on atleast one among the location, the size, and the shape of the currentblock, or based on an intra prediction technique of a neighboring block.For example, when the current block exists across a picture boundary, itmay be set not to apply the matrix-based intra prediction intraprediction to the current block.

The matrix-based intra prediction intra prediction is a method ofacquiring a prediction block of the current block by an encoder and adecoder based on a matrix product between a previously stored matrix andreconstructed samples in the neighborhood of the current block.Information for specifying any one among a plurality of previouslystored matrixes may be signaled through a bitstream. The decoder maydetermine a matrix for intra prediction of the current block based onthe information and the size of the current block.

The general intra prediction is a method of acquiring a prediction blockfor the current block based on a non-angular intra prediction mode or anangular intra prediction mode. Hereinafter, a process of performingintra prediction based on general intra prediction will be described inmore detail with reference to the drawings.

FIG. 28 is a flowchart illustrating an intra prediction method accordingto an embodiment of the present disclosure.

A reference sample line of the current block may be determined (S2801).The reference sample line means a set of reference samples included in ak-th line apart from the top and/or the left side of the current block.The reference samples may be derived from reconstructed samples thathave been encoded/decoded in the neighborhood of the current block.

Index information for identifying the reference sample line of thecurrent block among a plurality of reference sample lines may besignaled through a bitstream. The plurality of reference sample linesmay include at least one among a first line, a second line, a thirdline, and a fourth line on the top and/or left side of the currentblock. Table 4 shows indexes assigned to the reference sample lines,respectively. In Table 4, it is assumed that the first line, the secondline, and the fourth line are used as reference sample line candidates.

TABLE 4 Index Reference sample lines 0 First reference sample line 1Second reference sample line 2 Fourth reference sample line

The reference sample line of the current block may be determined basedon at least one among the location, the size, and the shape of thecurrent block, or based on a prediction encoding mode of a neighboringblock. For example, when the current block is in contact with theboundary of a picture, a tile, a slice, or a coding tree unit, the firstreference sample line may be determined as the reference sample line ofthe current block.

The reference sample line may include top reference samples positionedon the top of the current block and left reference samples positioned onthe left side of the current block. The top reference samples and theleft reference samples may be derived from reconstructed samples in theneighborhood of the current block. The reconstructed samples may be in astate before the in-loop filter is applied.

FIG. 29 is a view showing reference samples included in each referencesample line.

According to the intra prediction mode of the current block, aprediction sample may be acquired by using at least one among referencesamples belonging to a reference sample line.

Next, the intra prediction mode of the current block may be determined(S2802). As for the intra prediction mode of the current block, at leastone among a non-angular intra prediction mode and an angular intraprediction mode may be determined as the intra prediction mode of thecurrent block. The non-angular intra prediction mode includes a planarmode and a DC mode, and the angular intra prediction mode includes 33 or65 modes between the bottom-left diagonal direction and the top-rightdiagonal direction.

FIG. 30 is a view showing intra prediction modes.

FIG. 30 (a) shows 35 intra prediction modes, and FIG. 30 (b) shows 67intra prediction modes.

A larger or smaller number of intra prediction modes than those shown inFIG. 30 may be defined.

A Most Probable Mode (MPM) may be set based on the intra prediction modeof a neighboring block adjacent to the current block. Here, theneighboring block may include a left neighboring block adjacent to theleft side of the current block and a top neighboring block adjacent tothe top of the current block. When the coordinates of the top-leftsample of the current block are (0, 0), the left neighboring block mayinclude a sample at the position of (−1, 0), (−1, H−1) or (−1, (H−1)/2).Here, H denotes the height of the current block. The top neighboringblock may include a sample at the position of (0, −1), (W−1, −1) or((W−1)/2, −1). Here, W denotes the width of the current block.

When the neighboring block is encoded by normal intra prediction, theMPM may be derived based on the intra prediction mode of the neighboringblock. Specifically, the intra prediction mode of the left neighboringblock may be set to variable candIntraPredModeA, and the intraprediction mode of the top neighboring block may be set to variablecandIntraPredModeB.

At this point, when the neighboring block is unavailable (e.g., when theneighboring block is not yet encoded/decoded or when the position of theneighboring block is outside the picture boundary), when the neighboringblock is encoded by matrix-based intra prediction, when the neighboringblock is encoded by inter prediction, or when the neighboring block isincluded in a coding tree unit different from the current block,variable candIntraPredModeX (here, X is A or B) derived based on theintra prediction mode of the neighboring block may be set as a defaultmode. Here, the default mode may include at least one among a planarmode, a DC mode, a vertical direction mode, and a horizontal directionmode.

Alternatively, when the neighboring block is encoded by matrix-basedintra prediction, an intra prediction mode corresponding to an indexvalue for specifying any one among the matrixes may be set tocandIntraPredModeX. To this end, a lookup table showing the mappingrelation between index values for specifying a matrix and intraprediction modes may be previously stored in the encoder and thedecoder.

MPMs may be derived based on variable candIntraPredModeA and variablecandIntraPredModeB. The number of MPMs included in an MPM list may bepreviously set in the encoder and the decoder. The number of MPMsincluded in the MPM list may be preset in the encoder and the decoder.For example, the number of MPMs may be 3, 4, 5 or 6. Alternatively,information indicating the number of MPMs may be signaled through abitstream. Alternatively, the number of MPMs may be determined based onat least one among the prediction encoding mode of the neighboring blockand the size and the shape of the current block.

In the embodiments described below, it is assumed that the number ofMPMs is 3, and the 3 MPMs will be referred to as MPM[0], MPM[1] andMPM[2]. When the number of MPMs is more than 3, the MPMs may beconfigured to include 3 MPMs described in the embodiments describedbelow.

When candIntraPredA and candIntraPredB are the same, and candIntraPredAis a planar mode or a DC mode, MPM[0] and MPM[1] may be set to a planarmode and a DC mode, respectively. MPM[2] may be set to a verticaldirection intra prediction mode, a horizontal direction intra predictionmode, or a diagonal direction intra prediction mode. The diagonaldirection intra prediction mode may be a bottom-left diagonal directionintra prediction mode, a top-left direction intra prediction mode, or atop-right direction intra prediction mode.

When candIntraPredA and candIntraPredB are the same, and candIntraPredAis an angular intra prediction mode, MPM[0] may be set to be the same ascandIntraPredA. MPM[1] and MPM[2] may be set to an intra prediction modesimilar to candIntraPredA, respectively. The intra prediction modesimilar to candIntraPredA may be an intra prediction mode in which thedifference between candIntraPredA and an index is ±1 or ±2. A modulooperation (%) and an offset may be used to derive the intra predictionmode similar to candIntraPredA.

When candIntraPredA and candIntraPredB are different, MPM[0] may be setto be the same as candIntraPredA, and MPM[1] may be set to be the sameas candIntraPredB. At this point, when both candIntraPredA andcandIntraPredB are the non-angular intra prediction mode, MPM[2] may beset to a vertical direction intra prediction mode, a horizontaldirection intra prediction mode, or a diagonal direction intraprediction mode. Alternatively, when at least one among candIntraPredAand candIntraPredB is an angular intra prediction mode, MPM[2] may beset to an intra prediction mode derived by adding or subtracting anoffset to or from a planar mode, a DC mode, or one among candIntraPredAand candIntraPredB having a greater value. Here, the offset may be 1 or2.

An MPM list including a plurality of MPMs is generated, and informationindicating whether an MPM that is the same as the intra prediction modeof the current block is included in the MPM list may be signaled througha bitstream. The information is a 1-bit flag and may be referred to asan MPM flag. When the MPM flag indicates that an MPM the same as that ofthe current block is included in the MPM list, index informationidentifying one among the MPMs may be signaled through a bitstream. TheMPM specified by the index information may be set as the intraprediction mode of the current block. When the MPM flag indicates thatan MPM the same as that of the current block is not included in the MPMlist, residual mode information indicating any one among residual intraprediction modes other than MPMs may be signaled through a bitstream.The residual mode information indicates an index value corresponding tothe intra prediction mode of the current block when indexes arereassigned to the residual intra prediction modes excluding the MPMs.The decoder may arrange the MPMs in ascending order and determine theintra prediction mode of the current block by comparing the residualmode information with the MPMs. For example, when the residual modeinformation is equal to or smaller than the MPM, the intra predictionmode of the current block may be derived by adding 1 to the residualmode information.

Instead of setting the default mode to MPM, information indicatingwhether or not the intra prediction mode of the current block is thedefault mode may be signaled through a bitstream. The information is a1-bit flag, and the flag may be referred to as a default mode flag. Thedefault mode flag may be signaled only when the MPM flag indicates thatan MPM the same as that of the current block is included in the MPMlist. As described above, the default mode may include at least oneamong a planar mode, a DC mode, a vertical direction mode, and ahorizontal direction mode. For example, when the planar mode is set asthe default mode, the default mode flag may indicate whether or not theintra prediction mode of the current block is a planar mode. When thedefault mode flag indicates that the intra prediction mode of thecurrent block is not the default mode, one among the MPMs indicated bythe index information may be set as the intra prediction mode of thecurrent block.

When a plurality of intra prediction modes is set as default modes,index information indicating any one among the default modes may befurther signaled. The intra prediction mode of the current block may beset as the default mode indicated by the index information.

When the index of the reference sample line of the current block is not0, it may be set not to use the default mode. Accordingly, when theindex of the reference sample line is not 0, the default mode flag isnot signaled, and the value of the default mode flag may be set to apredefined value (i.e., false).

When the intra prediction mode of the current block is determined,prediction samples may be acquired for the current block based on thedetermined intra prediction mode (S2803).

When the DC mode is selected, prediction samples are generated for thecurrent block based on an average value of reference samples.Specifically, values of all the samples in a prediction block may begenerated based on an average value of the reference samples. Theaverage value may be derived using at least one among top referencesamples positioned on the top of the current block and left referencesamples positioned on the left side of the current block.

Depending on the shape of the current block, the number or range of thereference samples used for deriving the average value may vary. Forexample, when the current block is a non-square shaped block of whichthe width is greater than the height, the average value may becalculated using only the top reference samples. Contrarily, when thecurrent block is a non-square shaped block of which the width is smallerthan the height, the average value may be calculated using only the leftreference samples. That is, when the width and the height of the currentblock are different, the average value may be calculated using onlyreference samples adjacent to the longer one. Alternatively, based onthe ratio of width to height of the current block, whether or not tocalculate the average value using only the top reference samples orwhether or not to calculate the average value using only the leftreference samples may be determined.

When the planar mode is selected, a prediction sample may be acquiredusing a horizontal direction prediction sample and a vertical directionprediction sample. Here, the horizontal direction prediction sample isacquired based on a left reference sample and a right reference samplepositioned on a horizontal line the same as that of the predictionsample, and the vertical direction prediction sample is acquired basedon a top reference sample and a bottom reference sample positioned on avertical line the same as that of the prediction sample. Here, the rightreference sample may be generated by copying a reference sample adjacentto the top-right corner of the current block, and the bottom referencesample may be generated by copying a reference sample adjacent to thebottom-left corner of the current block. The horizontal directionprediction sample may be acquired based on a weighted sum operation ofthe left reference sample and the right reference sample, and thevertical direction prediction sample may be acquired based on a weightedsum operation of the top reference sample and the bottom referencesample. At this point, a weighting value assigned to each referencesample may be determined according to the position of the predictionsample. The prediction sample may be acquired based on an averageoperation or a weighted sum operation of the horizontal directionprediction sample and the vertical direction prediction sample. When theweighted sum operation is performed, weighting values applied to thehorizontal direction prediction sample and the vertical directionprediction sample may be determined based on the position of theprediction sample.

When an angular prediction mode is selected, a parameter indicating theprediction direction (or prediction angle) of the selected angularprediction mode may be determined. Table 5 shows intra directionparameter intraPredAng of each intra prediction mode.

TABLE 5 PredModeIntra 1 2 3 4 5 6 7 IntraPredAng — 32 26 21 17 13 9PredModeIntra 8 9 10 11 12 13 14 IntraPredAng 5 2 0 −2 −5 −9 −13PredModeIntra 15 16 17 18 19 20 21 IntraPredAng −17 −21 −26 −32 −26 −21−17 PredModeIntra 22 23 24 25 26 27 28 IntraPredAng −13 −9 −5 −2 0 2 5PredModeIntra 29 30 31 32 33 34 IntraPredAng 9 13 17 21 26 32

When 35 intra prediction modes are defined, Table 5 shows the intradirection parameter of each intra prediction mode having an index of anyone among 2 to 34. When more than 33 angular intra prediction modes aredefined, Table 5 is further subdivided to set the intra directionparameter of each angular intra prediction mode.

After arranging top reference samples and left reference samples of thecurrent block in a line, a prediction sample may be acquired based onthe value of the intra direction parameter. At this point, when thevalue of the intra direction parameter is a negative value, the leftreference samples and the top reference samples may be arranged in aline.

FIGS. 31 and 32 are views showing an example of a one-dimensional arrayarranging reference samples in a line.

FIG. 31 is a view showing an example of a vertical directionone-dimensional array arranging reference samples in the verticaldirection, and FIG. 32 is a view showing an example of a horizontaldirection one-dimensional array arranging reference samples in thehorizontal direction. The embodiments of FIGS. 31 and 32 will bedescribed on the assumption that 35 intra prediction modes are defined.

When the intra prediction mode index is any one among 11 to 18, ahorizontal direction one-dimensional array in which top referencesamples are rotated counterclockwise may be applied, and when the intraprediction mode index is any one among 19 to 25, a vertical directionone-dimensional array in which left reference samples are rotatedclockwise may be applied. In arranging the reference samples in a line,an intra prediction mode angle may be considered.

A reference sample determination parameter may be determined based on anintra direction parameter. The reference sample determination parametermay include a reference sample index for specifying a reference sampleand a weighting value parameter for determining a weighting valueapplied to the reference sample.

Reference sample index iIdx and weighting value parameter infact may beacquired through Equations 5 and 6 shown below, respectively.ildx=(y+1)*P _(ang)/32  [Equation 5]i _(fact)=[(y+1)*P _(ang)]&31  [Equation 6]

In Equations 5 and 6, P_(ang) denotes an intra direction parameter. Thereference sample specified by reference sample index ildx corresponds toan integer pel.

At least one or more reference samples may be specified to derive aprediction sample. Specifically, the position of a reference sample usedfor deriving a prediction sample may be specified considering the slopeof the prediction mode. For example, a reference sample used forderiving a prediction sample may be specified using reference sampleindex ildx.

At this point, when the slope of the intra prediction mode is notexpressed by one reference sample, a prediction sample may be generatedby interpolating a plurality of reference samples. For example, when theslope of the intra prediction mode is a value between a slope between aprediction sample and a first reference sample and a slope between aprediction sample and a second reference sample, the prediction samplemay be acquired by interpolating the first reference sample and thesecond reference sample. That is, when an angular line following anintra prediction angle does not pass through a reference samplepositioned at an integer pel, the prediction sample may be acquired byinterpolating reference samples adjacent to the left and right or up anddown sides of a position where the angular line passes through.

Equation 7 shows an example of acquiring a prediction sample based onreference samples.P(x,y)=((32−i _(fact))/32)*Ref_1D(x+ildx+1)(i_(fact)/32)*Ref_1D(x+ildx+2)  [Equation 7]

In Equation 7, P denotes a prediction sample, and Ref_1D denotes any oneamong one-dimensionally arranged reference samples. At this point, theposition of a reference sample may be determined by position (x, y) ofthe prediction sample and index ildx of the reference sample.

When the slope of the intra prediction mode can be expressed as onereference sample, weighting value parameter i_(fact) is set to 0.Accordingly, Equation 7 may be simplified as shown in Equation 8.P(x,y)=Ref_1D(x+ildx+1)  [Equation 8]

Intra prediction for the current block may be performed based on aplurality of intra prediction modes. For example, an intra predictionmode may be derived for each prediction sample, and the predictionsample may be derived based on an intra prediction mode assigned to eachprediction sample.

Alternatively, an intra prediction mode may be derived for each region,and intra prediction for each region may be performed based on the intraprediction mode assigned to each region. Here, the region may include atleast one sample. At least one among the size and the shape of theregion may be adaptively determined based on at least one among thesize, the shape, and the intra prediction mode of the current block.Alternatively, at least one among the size and the shape of the regionmay be predefined in the encoder and the decoder to be independent fromthe size or the shape of the current block.

Alternatively, intra prediction may be performed based on each of aplurality of intra predictions, and a final prediction sample may bederived based on an average operation or a weighted sum operation of aplurality of prediction samples acquired through the plurality of intrapredictions. For example, a first prediction sample may be acquired byperforming intra prediction based on a first intra prediction mode, anda second prediction sample may be acquired by performing intraprediction based on a second intra prediction mode. Thereafter, a finalprediction sample may be acquired based on an average operation or aweighted sum operation of the first prediction sample and the secondprediction sample. At this point, a weighting value assigned to each ofthe first prediction sample and the second prediction sample may bedetermined considering at least one among whether or not the first intraprediction mode is a non-angular/angular prediction mode, whether or notthe second intra prediction mode is a non-angular/angular predictionmode, and an intra prediction mode of a neighboring block.

The plurality of intra prediction modes may be a combination of anon-angular intra prediction mode and an angular prediction mode, acombination of angular prediction modes, or a combination of non-angularprediction modes.

FIG. 33 is a view showing an example of angles formed between angularintra prediction modes and a straight line parallel to the x-axis.

As shown in the example of FIG. 33 , the angular prediction modes mayexist between the bottom-left diagonal direction and the top-rightdiagonal direction. Describing in terms of an angle formed by the x-axisand the angular prediction mode, the angular prediction modes may existbetween 45 degrees (bottom-left diagonal direction) and −135 degrees(top-right diagonal direction).

When the current block is a non-square shape, according to the intraprediction mode of the current block, there may be a case of deriving aprediction sample by using a reference sample farther from theprediction sample, instead of a reference sample further closer to theprediction sample, among the reference samples positioned on the angularline following the intra prediction angle.

FIG. 34 is a view showing an embodiment of acquiring prediction sampleswhen the current block is a non-square shape.

For example, as shown in the example of FIG. 34 (a), it is assumed thatthe current block is a non-square shape of which the width is greaterthan the height, and the intra prediction mode of the current block isan angular intra prediction mode having an angle between 0 and 45degrees. In the above case, when prediction sample A near the rightcolumn of the current block is derived, there may be a case of usingleft reference sample L far from the prediction sample, instead of topreference sample T close to the prediction sample, among the referencesamples positioned on an angular mode following the angle.

As another example, as shown in the example of FIG. 34 (b), it isassumed that the current block is a non-square shape of which the heightis greater than the width, and the intra prediction mode of the currentblock is an angular intra prediction mode having an angle between −90and −135 degrees. In the above case, when prediction sample A near thebottom row of the current block is derived, there may be a case of usingtop reference sample T far from the prediction sample, instead of leftreference sample L close to the prediction sample, among the referencesamples positioned on an angular mode following the angle.

To solve the problem described above, when the current block is anon-square shape, the intra prediction mode of the current block may bereplaced with an intra prediction mode of the opposite direction.Accordingly, angular prediction modes having an angle greater or smallerthan that of the angular prediction modes shown in FIG. 34 may be usedfor a non-square shaped block. The angular intra prediction mode likethis may be defined as a wide-angle intra prediction mode. Thewide-angle intra prediction mode represents an angular intra predictionmode that does not belong to the range of 45 to −135 degrees.

FIG. 35 is a view showing wide-angle intra prediction modes.

In the example shown in FIG. 35 , intra prediction modes with an indexof −1 to −14 and intra prediction modes with an index of 67 to 80represent wide-angle intra prediction modes.

Although 14 wide-angle intra prediction modes (−1 to −14) having anangle larger than 45 degrees and 14 wide-angle intra prediction modes(67 to 80) having an angle smaller than −135 degrees are shown in FIG.35 , a larger or smaller number of wide-angle intra prediction modes maybe defined.

When a wide-angle intra prediction mode is used, the length of topreference samples may be set to 2W+1, and the length of left referencesamples may be set to 2H+1.

As a wide-angle intra prediction mode is used, sample A shown in FIG. 34(a) may be predicted using reference sample T, and sample A shown inFIG. 34 (b) may be predicted using reference sample L.

By adding existing intra prediction modes and N wide-angle intraprediction modes, a total of 67+N intra prediction modes can be used.For example, Table 6 shows intra direction parameters of intraprediction modes when 20 wide-angle intra prediction modes are defined.

TABLE 6 PredModeIntra −10 −9 −8 −7 −6 −5 −4 −3 −2 intraPredAngle 114 9379 68 60 54 49 45 39 PredModeIntra −1 2 3 4 5 6 7 8 9 intraPredAngle 3532 29 26 23 21 19 17 15 PredModeIntra 10 11 12 13 14 15 16 17 18intraPredAngle 13 11 9 7 5 3 2 1 0 PredModeIntra 19 20 21 22 23 24 25 2627 intraPredAngle −1 −2 −3 −5 −7 −9 −11 −13 −15 PredModeIntra 28 29 3031 32 33 34 35 36 intraPredAngle −17 −19 −21 −23 −26 −29 −32 −29 −26PredModeIntra 37 38 39 40 41 42 43 44 45 intraPredAngle −23 −21 −19 −17−15 −13 −11 −9 −7 PredModeIntra 46 47 48 49 50 51 52 53 54intraPredAngle −5 −3 −2 −1 0 1 2 3 5 PredModeIntra 55 56 57 58 59 60 6162 63 intraPredAngle 7 9 11 13 15 17 19 21 23 PredModeIntra 64 65 66 6768 69 70 71 72 intraPredAngle 26 29 32 35 39 45 49 54 60 PredModeIntra73 74 75 76 intraPredAngle 68 79 93 114

When the current block is a non-square shape and the intra predictionmode of the current block acquired at step S2802 belongs to a transformrange, the intra prediction mode of the current block may be transformedinto a wide-angle intra prediction mode. The transform range may bedetermined based on at least one among the size, the shape, and theratio of the current block. Here, the ratio may represent a ratio ofwidth to height of the current block.

When the current block is a non-square shape of which the width isgreater than the height, the transform range may be set from an intraprediction mode index (e.g., 66) of the top-right diagonal direction (anindex of the intra prediction mode in the top-right diagonaldirection−N). Here, N may be determined based on the ratio of thecurrent block. When the intra prediction mode of the current blockbelongs to the transform range, the intra prediction mode may betransformed into a wide-angle intra prediction mode. The transform maybe subtraction of a predefined value from the intra prediction mode, andthe predefined value may be the total number (e.g., 67) of intraprediction modes excluding the wide-angle intra prediction modes.

According to the embodiment described above, 66th to 53rd intraprediction modes may be transformed into −1st to −14th wide-angle intraprediction modes, respectively.

When the current block is a non-square shape of which the height isgreater than the width, the transform range may be set from an intraprediction mode index (e.g., 2) of the bottom-left diagonal direction(an index of the intra prediction mode in the bottom-left diagonaldirection+M). Here, M may be determined based on the ratio of thecurrent block. When the intra prediction mode of the current blockbelongs to the transform range, the intra prediction mode may betransformed into a wide-angle intra prediction mode. The transform maybe addition of a predefined value to the intra prediction mode, and thepredefined value may be the total number (e.g., 65) of angular intraprediction modes excluding the wide-angle intra prediction modes.

According to the embodiment described above, 2nd to 15th intraprediction modes may be transformed into 67th to 80th wide-angle intraprediction modes, respectively.

Hereinafter, intra prediction modes belonging to the transform rangewill be referred to as wide-angle intra replacement prediction modes.

The transform range may be determined based on the ratio of the currentblock. For example, Tables 7 and 8 show a transform range when 35 intraprediction modes and 67 intra prediction modes are defined excluding thewide-angle intra prediction modes, respectively.

TABLE 7 Condition Replaced Intra Prediction Modes W/H = 2 Modes 2, 3, 4W/H > 2 Modes 2, 3, 4, 5, 6 W/H = 1 None H/W = 1/2 Modes 32, 33, 34 H/W< 1/2 Modes 30, 31, 32, 33, 34

TABLE 8 Condition Replaced Intra Prediction Modes W/H = 2 Modes 2, 3, 4,5, 6, 7 W/H > 2 Modes 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 W/H = 1 None H/W =1/2 Modes 61, 62, 63, 64, 65, 66 H/W < 1/2 Modes 57, 58, 59, 60, 61, 62,63, 64, 65, 66

As shown in the examples of Tables 7 and 8, the number of wide-angleintra replacement prediction modes belonging to the transform range mayvary according to the ratio of the current block.

As the wide-angle intra prediction modes are used in addition to theexisting intra prediction modes, resources required for encoding thewide-angle intra prediction modes increase, and thus encoding efficiencymay be lowered. Accordingly, the encoding efficiency may be improved byencoding replacement intra prediction modes for the wide-angle intraprediction modes, instead of encoding the wide-angle intra predictionmodes as they are.

For example, when the current block is encoded using the 67th wide-angleintra prediction mode, the 2nd intra prediction mode, which is thereplacement intra prediction mode of the 67th wide-angle intraprediction mode, may be encoded using the intra prediction mode of thecurrent block. In addition, when the current block is encoded using the−1st wide-angle intra prediction mode, the 66th intra prediction mode,which is the replacement intra prediction mode of the −1st wide-angleintra prediction mode, may be encoded using the intra prediction mode ofthe current block.

The decoder may decode the intra prediction mode of the current blockand determine whether the decoded intra prediction mode belongs to thetransform range. When the decoded intra prediction mode is a wide-anglereplacement intra prediction mode, the intra prediction mode may betransformed into the wide-angle intra prediction mode.

Alternatively, when the current block is encoded using the wide-angleintra prediction mode, the wide-angle intra prediction mode may beencoded as it is.

Encoding the intra prediction mode may be performed based on the MPMlist described above. Specifically, when a neighboring block is encodedusing a wide-angle intra prediction mode, the MPM may be set based on awide-angle replacement intra prediction mode corresponding to thewide-angle intra prediction mode. For example, when a neighboring blockis encoded using a wide-angle intra prediction mode, variablecandIntraPredX (X is A or B) may be set to the wide-angle replacementintra prediction mode.

When a prediction block is generated as a result of performing the intraprediction, prediction samples may be updated based on the position ofeach of the prediction samples included in the prediction block. Theupdate method like this may be referred to as an intra weightedprediction method based on a sample position or Position Dependent intraPrediction Combination (PDPC).

Whether or not to use the PDPC may be determined considering the intraprediction mode of the current block, the reference sample line of thecurrent block, the size of the current block, or a color component. Forexample, when the intra prediction mode of the current block is at leastone among of a planar mode, a DC mode, a vertical direction mode, ahorizontal direction mode, a mode having an index value smaller thanthat or the vertical direction mode, and a mode having an index valuelarger than that of the horizontal direction mode, the PDPC may be used.Alternatively, only when at least one among the width and the height ofthe current block is greater than 4, the PDPC may be used.Alternatively, only when the index of the reference picture line of thecurrent block is 0, the PDPC may be used. Alternatively, only when theindex of the reference picture line of the current block is equal to orgreater than a predefined value, the PDPC may be used. Alternatively,PDPC may be used only for a luminance component. Alternatively,depending on whether or not two or more of the conditions listed aboveare satisfied, whether or not to use the PDPC may be determined.

As another example, information indicating whether or not the PDPC isapplied may be signaled through a bitstream.

When a prediction sample is acquired through the intra predictionsample, a reference sample used for correcting the prediction sample maybe determined based on the position of the acquired prediction sample.For convenience of explanation, in the embodiment described below, areference sample used for correcting a prediction sample is referred toas a PDPC reference sample. In addition, a prediction sample acquiredthrough intra prediction is referred to as a first prediction sample,and a prediction sample acquired by correcting the first predictionsample is referred to as a second prediction sample.

FIG. 36 is a view showing an embodiment of applying PDPC.

The first prediction sample may be corrected using at least one PDPCreference sample. The PDPC reference sample may include at least oneamong a reference sample adjacent to the top-left corner of the currentblock, a top reference sample positioned on the top of the currentblock, and a left reference sample positioned on the left side of thecurrent block.

At least one among the reference samples belonging to the referencesample line of the current block may be set as the PDPC referencesample. Alternatively, regardless of the reference sample line of thecurrent block, at least one among the reference samples belonging to thereference sample line having index 0 may be set as the PDPC referencesample. For example, although the first prediction sample is acquiredusing a reference sample included in a reference sample line of index 1or index 2, the second prediction sample may be acquired using areference sample included in the reference sample line of index 0.

The number or positions of the PDPC reference samples used forcorrecting the first prediction sample may be determined considering atleast one among the intra prediction mode of the current block, the sizeof the current block, the shape of the current block, and the positionof the first prediction sample.

For example, when the intra prediction mode of the current block is aplanar mode or a DC mode, the second prediction sample may be acquiredusing a top reference sample and a left reference sample. At this point,the top reference sample may be a reference sample vertical to the firstprediction sample (e.g., a reference sample of the same x-coordinate),and the left reference sample may be a reference sample horizontal tothe first prediction sample (e.g., a reference sample of the samey-coordinate).

When the intra prediction mode of the current block is a horizontaldirection intra prediction mode, the second prediction sample may beacquired using a top reference sample. At this point, the top referencesample may be a reference sample vertical to the first predictionsample.

When the intra prediction mode of the current block is a verticaldirection intra prediction mode, the second prediction sample may beacquired using a left reference sample. At this point, the leftreference sample may be a reference sample horizontal to the firstprediction sample.

When the intra prediction mode of the current block is a bottom-leftdiagonal direction intra prediction mode or a top-right diagonaldirection intra prediction mode, the second prediction sample may beacquired based on a top-left reference sample, a top reference sample,and a left reference sample. The top-left reference sample may be areference sample adjacent to the top-left corner of the current block(e.g., a reference sample at the position of (−1, −1)). The topreference sample may be a reference sample positioned in the top-rightdiagonal direction of the first prediction sample, and the leftreference sample may be a reference sample positioned in the bottom-leftdiagonal direction of the first prediction sample.

In summary, when the position of the first prediction sample is (x, y),R (−1, −1) may be set as the top-left reference sample, and R (x+y+1,−1) or R (x, −1) may be set as the top reference sample. In addition, R(−1, x+y+1) or R (−1, y) may be set as the left reference sample.

As another example, the position of the left reference sample or the topreference sample may be determined considering at least one among theshape of the current block and whether or not the wide-angle intra modeis applied.

Specifically, when the intra prediction mode of the current block is awide-angle intra prediction mode, a reference sample spaced apart from areference sample positioned in the diagonal direction of the firstprediction sample as much as an offset may be set as the PDPC referencesample. For example, top reference sample R (x+y+k+1, −1) and leftreference sample R (−1, x+y−k+1) may be set as PDPC reference samples.

At this point, offset k may be determined based on a wide-angle intraprediction mode. Equations 9 and 10 show an example of deriving anoffset based on a wide-angle intra prediction mode.k=CurrIntraMode−66if(CurrintraMode>66)  [Equation 9]k=−CurrIntraMode if(CurrIntraMode<0)  [Equation 10]

The second prediction sample may be determined based on a weighted sumoperation of the first prediction sample and the PDPC reference samples.For example, the second prediction sample may be acquired based onEquation 11 shown below.pred(x,y)=(xL*R _(L) +wT*R _(T) −wTL*R_(TL)+(64−wL−wT+wTL)*pred(x,y)+32)>>6  [Equation 11]

In Equation 11, R_(L) denotes a left reference sample, R_(T) denotes atop reference sample, and R_(TL) denotes a top-left reference sample.pred (x, y) denotes a prediction sample at the position of (x, y). wLdenotes a weighting value assigned to the left reference sample, wTdenotes a weighting value assigned to the top reference sample, and wTLdenotes a weighting value assigned to the top-left reference sample. Theweighting values assigned to the first prediction sample may be derivedby subtracting weighting values assigned to the reference samples fromthe maximum value. For convenience of explanation, a weighting valueassigned to a PDPC reference sample is referred to as a PDPC weightingvalue.

A weighting value assigned to each reference sample may be determinedbased on at least one among the intra prediction mode of the currentblock and the position of the first prediction sample.

For example, at least one among wL, wT and wTL may have a proportionalor inverse proportional relation with at least one among the x-axiscoordinate value and the y-axis coordinate value of the predictionsample. Alternatively, at least one among wL, wT and wTL may have aproportional or inversely proportional relation with at least one amongthe width and the height of the current block.

When the intra prediction mode of the current block is a DC mode, PDPCweighting values may be determined as shown in Equation 12.wT=32>>((y<<1)>>shift)wL=32>>((x<<1)>>shift)wTL=(wL>>4)+(wT>>4)  [Equation 12]

In Equation 12, x and y denote the position of the first predictionsample.

Variable shift used in the bit shift operation in Equation 12 may bederived based on the width or the height of the current block. Forexample, variable shift may be derived based on Equation 13 or 14 shownbelow.shift=(log₂(width)−2+log₂(height)−2+2)>>2  [Equation 13]shift=((Log₂(nTbW)+Log₂(nTbH)−2)>>2)  [Equation 14]

Alternatively, variable shift may be derived considering the intradirection parameter of the current block.

The number of parameters or parameter types used for deriving variableshift may be determined differently according to the intra predictionmode of the current block. For example, when the intra prediction modeof the current block is a planar mode, a DC mode, a vertical directionmode, or a horizontal direction mode, variable shift may be derivedusing the width and the height of the current block as shown in theexample of Equation 13 or Equation 14. When the intra prediction mode ofthe current block is an intra prediction mode having an index largerthan that of the vertical direction intra prediction mode, variableshift may be derived using the height and the intra direction parameterof the current block. When the intra prediction mode of the currentblock is an intra prediction mode having an index smaller than that ofthe horizontal intra prediction mode, variable shift may be derivedusing the width and the intra direction parameter of the current block.

When the intra prediction mode of the current block is a planar mode,the value of wTL may be set to 0. wL and wT may be derived based onEquation 15 shown below.wT[y]=32>>((y<<1)>>nScale)wL[x]=32>>((x<<1)>>nScale)  [Equation 15]

When the intra prediction mode of the current block is a horizontaldirection intra prediction mode, wT may be set to 0, and wTL and wL maybe set equally. Contrarily, when the intra prediction mode of thecurrent block is a vertical direction intra prediction mode, wL may beset to 0, and wTL and wT may be set equally.

When the intra prediction mode of the current block is an intraprediction mode directing toward the top-right having an index valuelarger than that of the intra prediction mode of the vertical direction,PDPC weighting values may be derived as shown in Equation 16.wT=16((y<<1)>>shift)wL=16((x<<1)>>shift)wTL=0  [Equation 16]

Contrarily, when the intra prediction mode of the current block is anintra prediction mode directing toward the bottom-left having an indexvalue smaller than that of the intra prediction mode of the horizontaldirection, the PDPC weighting values may be derived as shown in Equation17.wT16>>(y<<1)>>shift)wL=16>>((x<<1)>>shift)wTL=0  [Equation 17]

As shown in the embodiment described above, PDPC weighting values may bedetermined based on the position x and y of the prediction sample.

As another example, a weighting value assigned to each of the PDPCreference samples may be determined by the unit of subblock. Predictionsamples included in a subblock may share the same PDPC weighting values.

The size of a subblock, which is a basic unit for determining aweighting value, may be predefined in the encoder and the decoder. Forexample, a weighting value may be determined for each subblock of a 2×2or 4×4 size.

Alternatively, the size, the shape, or the number of subblocks may bedetermined according to the size or the shape of the current block. Forexample, regardless of the size of a coding block, the coding block maybe divided into four subblocks. Alternatively, the coding block may bedivided into 4 or 16 subblocks according to the size of the codingblock.

Alternatively, the size, the shape, or the number of subblocks may bedetermined based on the intra prediction mode of the current block. Forexample, when the intra prediction mode of the current block is in thehorizontal direction, N columns (or N rows) are set as one subblock,whereas when the intra prediction mode of the current block is in thevertical direction, N rows (or N columns) may be set as one subblock.

Equations 18 to 20 show examples of determining a PDPC weighting valuefor a subblock of a 2×2 size. Equation 18 shows a case in which theintra prediction mode of the current block is a DC mode.wT=32>>(((y<<log₂ K))>>log₂ K)<<1)>>shift)wL=32>>(((x<<log 2K))>>log 2K)<<1)>>shift)wTL=(wL>>4)+(wT>>4)  [Equation 18]

In Equation 18, K may be determined based on the size of a subblock.

Equation 19 shows an example in which the intra prediction mode of thecurrent block is an intra prediction mode directing toward the top-righthaving an index value larger than that of the intra prediction mode ofthe vertical direction.wT=16>>log₂ K))>>log₂ K))<<1)>>shift)wL=16>>(((x<<log 2K))>>log 2K))<<1)>>shift)wTL=0  [Equation 19]

Equation 20 shows an example in which the intra prediction mode of thecurrent block is an intra prediction mode directing toward thebottom-left having an index value smaller than that of the intraprediction mode of the horizontal direction.wT=16>>(((y<<log₂ K))>>log₂ K))<<1)>>shift)wL=16>>(((x<<log 2K))>>log 2K))<<1)>>shift)wTL=0  [Equation 20]

In Equations 18 to 20, x and y denotes the position of a referencesample within a subblock. The reference sample may be any one among asample positioned at the top-left of the subblock, a sample positionedat the center of the subblock, and a sample positioned at thebottom-right of the subblock.

Equations 21 to 23 show examples of determining a PDPC weighting valuefor a subblock of a 4×4 size. Equation 21 shows an example in which theintra prediction mode of the current block is a DC mode.wT=32>>(((y<<2))>>2)<<1)>>shift)wL=32>>(((x<<2))>>2)<<1)>>shift)wTL=(wL>>4)+(wT>>4)  [Equation 21]

Equation 22 shows an example in which the intra prediction mode of thecurrent block is an intra prediction mode directing toward the top-righthaving an index value larger than that of the intra prediction mode ofthe vertical direction.wT=16>>(((y<<2))>>2)<<1)>>shift)wL=16>>(((x<<2))>>2)<<1)>>shift)wTL=0  [Equation 22]

Equation 23 shows an example in which the intra prediction mode of thecurrent block is an intra prediction mode directing toward thebottom-left having an index value smaller than that of the intraprediction mode of the horizontal direction.wT=16>>(((y<<2))>>2)<<1)>>shift)wL=16>>(((x<<2))>>2)<<1)>>shift)wTL=0  [Equation 23]

In the embodiments described above, it has been described that PDPCweighting values are determined considering the positions of theprediction samples included in a first prediction sample or a subblock.The PDPC weighting values may be determined by further considering theshape of the current block.

For example, in the case of a DC mode, the method of deriving a PDPCweighting value may vary depending on whether the current block is anon-square shape of which the width is greater than the height or anon-square shape of which the height is greater than the width.

Equation 24 shows an example of deriving a PDPC weighting value when thecurrent block is a non-square shape of which the width is greater thanthe height, and Equation 25 shows an example of deriving a PDPCweighting value when the current block is a non-square shape of whichthe height is greater than the width.wT=32>>((y<<1)>>shift)wL=32>>(x>>shift)wTL=(wL>>4)+(wT>>4)  [Equation 24]wT>>(y>>shift)wL=32>>((x<<1)>>shift)wTL=(wL>>4)+(wT>>4)  [Equation 25]

When the current block is a non-square shape, the current block may bepredicted using a wide-angle intra prediction mode. In this way, evenwhen the wide-angle intra prediction mode is applied, the firstprediction sample may be updated by applying the PDPC.

When the wide-angle intra prediction is applied to the current block,the PDPC weighting value may be determined considering the shape of thecoding block.

For example, when the current block is a non-square shape of which thewidth is greater than the height, according to the position of the firstprediction sample, there may be a case in which the top reference samplepositioned at the top-right of the first prediction sample is closer tothe first prediction sample than the left reference sample positioned atthe bottom-left of the first prediction sample. Accordingly, incorrecting the first prediction sample, the weighting value applied tothe top reference sample may be set to have a value larger than theweighting value applied to the left reference sample.

Contrarily, when the current block is a non-square shape of which theheight is greater than the width, according to the position of the firstprediction sample, there may be a case in which the left referencesample positioned at the bottom-left of the first prediction sample iscloser to the first prediction sample than the top reference samplepositioned at the top-right of the first prediction sample. Accordingly,in correcting the first prediction sample, the weighting value appliedto the left reference sample may be set to have a value larger than theweighting value applied to the top reference sample.

Equation 26 shows an example of deriving a PDPC weighting value when theintra prediction mode of the current block is a wide-angle intraprediction mode having an index larger than 66.wT=16>>(y>>shift)wL=16>>((x<<1)>>shift)wTL=0  [Equation 26]

Equation 27 shows an example of deriving a PDPC weighting value when theintra prediction mode of the current block is a wide-angle intraprediction mode having an index smaller than 0.wT=16>>((y<<1)>>shift)wL=16>>(x>>shift)wTL=0  [Equation 27]

The PDPC weighting value may be determined based on the ratio of thecurrent block. The ratio of the current block represents a ratio ofwidth to height of the current block, and may be defined as shown inEquation 28.whRatio=CUwidth/CUheight  [Equation 28]

According to the intra prediction mode of the current block, the methodof deriving the PDPC weighting value may be determined in various ways.

For example, Equations 29 and 30 show an example of deriving a PDPCweighting value when the intra prediction mode of the current block is aDC mode. Specifically, Equation 29 is an example of a case where thecurrent block is a non-square shape of which the width is greater thanthe height, and Equation 30 is an example of a case where the currentblock is a non-square shape of which the height is greater than thewidth.wT=32>>((y<<1)>>shift)wL=32>>(((x<<1)>>whRatio)>>shift)wTL=(wL>>4)+(wT>>4)  [Equation 29]wT=32>>(((y<<1)>>1/whRatio)>>shift)wL=32>>((x<<1)>>shift)wTL=(wL>>4)+(wT>>4)  [Equation 30]

Equation 31 shows an example of deriving a PDPC weighting value when theintra prediction mode of the current block is a wide-angle intraprediction mode having an index larger than 66.wT=16>>(((y<<1)>>1/whRatio)>>shift)wL=16>>((x<<1)>>shift)wTL=0  [Equation 31]

Equation 32 shows an example of deriving a PDPC weighting value when theintra prediction mode of the current block is a wide-angle intraprediction mode having an index smaller than 0.wT=16>>(y<<1)>>shift)wL=16>>(((x<<1)>>whRatio)>>shift)wTL=0  [Equation 32]

A prediction mode may be applied to the current block a plurality oftimes, or a plurality of prediction modes may be redundantly applied tothe current block. Like this, a prediction method using a homogeneous orheterogeneous prediction mode may be referred to as a combinedprediction mode (or Multi-hypothesis Prediction Mode).

Information indicating whether the combined prediction mode is appliedto the current block may be signaled through a bitstream. For example,the information may be a 1-bit flag.

In the combined prediction mode, a first prediction block may begenerated based on the first prediction mode, and a second predictionblock may be generated based on the second prediction mode. Then, athird prediction block may be generated based on a weighted sumoperation of the first prediction block and the second prediction block.The third prediction block may be set as the final prediction block ofthe current block.

The combined prediction mode includes at least one among a modecombining a merge mode and a merge mode, a mode combining interprediction and intra prediction, a mode combining a merge mode and amotion vector prediction mode, and a mode combining a merge mode andintra prediction.

In the mode combining a merge mode and a merge mode, motion compensationprediction may be performed using a plurality of merge candidates.Specifically, a first prediction block may be generated using a firstmerge candidate, and a second prediction block may be generated using asecond merge candidate. A third prediction block may be generated basedon a weighted sum operation of the first prediction block and the secondprediction block.

Information for specifying the first merge candidate and the secondmerge candidate may be signaled through a bitstream, respectively. Forexample, index information merge_idx for specifying the first mergecandidate and index information merge_2nd_idx for specifying the secondmerge candidate may be signaled through a bitstream. The second mergecandidate may be determined based on index information merge_2nd_idx andindex information merge_idx.

Index information merge_idx specifies any one among merge candidatesincluded in the merge candidate list.

Index information merge_2nd_idx may specify any one among the remainingmerge candidates excluding the merge candidate specified by merge_idx.Accordingly, when the value of merge_2nd_idx is smaller than that ofmerge_idx, a merge candidate of which the index is the value ofmerge_2nd_idx may be set as the second merge candidate. When the valueof merge_2nd_idx is equal to or greater than the value of merge_idx, amerge candidate having a value obtained by adding 1 to the value ofmerge_2nd_idx as an index may be set as the second merge candidate.

Alternatively, the second merge candidate may be specified consideringthe search order of candidate blocks.

FIG. 37 is a view showing an example in which a second merge candidateis specified considering the search order of candidate blocks.

In the example shown in FIG. 37 , indexes marked on neighboring samplesand non-neighboring samples indicate the search order of candidateblocks. For example, candidate blocks may be sequentially searched fromposition A0 to position A14.

When block A4 is selected as the first merge candidate, a mergecandidate derived from a candidate block having a search order next toA4 may be specified as the second merge candidate. For example, a mergecandidate derived from A5 may be selected as the second merge candidate.When the candidate block at position A5 cannot be used as a mergecandidate, a merge candidate derived from a next candidate block may beselected as the second merge candidate.

The first merge candidate and the second merge candidate may be selectedamong merge candidates derived from non-neighbor blocks.

FIG. 38 is a view showing an example in which a first merge candidateand a second merge candidate are selected among merge candidates derivedfrom non-neighboring blocks.

As shown in the example of FIG. 38 , merge candidates derived from afirst candidate block and a second candidate block that are not adjacentto the current block may be selected as the first merge candidate andthe second merge candidate, respectively. At this point, the block lineto which the first candidate block belongs and the block line to whichthe second candidate block belongs may be different. For example, thefirst merge candidate may be derived from any one among candidate blocksA5 to A10, and the second merge candidate may be derived from any oneamong candidate blocks A11 to A15.

Alternatively, it may be set such that the first candidate block and thesecond candidate block are not included in the same line (e.g., row orcolumn).

As another example, the second merge candidate may be specified based onthe first merge candidate. At this point, the first merge candidate maybe specified by the index information merge_idx signaled from abitstream. For example, a merge candidate adjacent to the first mergecandidate may be specified as the second merge candidate. Here, themerge candidate adjacent to the first merge candidate may mean a mergecandidate having an index difference of 1 with respect to the firstmerge candidate. For example, a merge candidate having an index value ofmerge_idx+1 may be set as the second merge candidate. At this point,when the value of merge_idx+1 is larger than the maximum index value (orwhen the index value of the first merge candidate is the maximum index),a merge candidate having an index value of merge_idx−1 or a mergecandidate having an index value of a predefined value (e.g., 0) may beset as the second merge candidate.

Alternatively, the merge candidate adjacent to the first merge candidatemay mean a merge candidate derived from a candidate block spatiallyadjacent to a candidate block used for deriving the first mergecandidate. Here, the neighboring candidate block of the candidate blockmay mean a block adjacent to the candidate block in the left, right,top, bottom, or diagonal direction.

As another example, the second merge candidate may be specified based onmotion information of the first merge candidate. For example, a mergecandidate sharing the same reference picture with the first mergecandidate may be selected as the second merge candidate. When there is aplurality of merge candidates sharing the same reference picture withthe first merge candidate, a merge candidate having the smallest indexamong the plurality of merge candidates or a merge candidate having thesmallest index difference with respect to the first merge candidate maybe selected as the second merge candidate. Alternatively, the secondmerge candidate may be selected based on index information specifyingany one among the plurality of merge candidates.

Alternatively, when the first merge candidate is unidirectionalprediction of a first direction, a merge candidate including motioninformation in a second direction may be set as the second mergecandidate. For example, when the first merge candidate has motioninformation of direction L0, a merge candidate having motion informationof direction L1 may be selected as the second merge candidate. Whenthere is a plurality of merge candidates having motion information ofdirection L1, a merge candidate having the smallest index or a mergecandidate having the smallest index difference with respect to the firstmerge candidate among the plurality of merge candidates may be set asthe second merge candidate. Alternatively, the second merge candidatemay be selected based on index information specifying any one among theplurality of merge candidates.

As another example, one among the merge candidates derived fromneighboring blocks adjacent to the current block may be set as the firstmerge candidate, and one among the merge candidates derived fromnon-neighbor blocks not adjacent to the current block may be set as thesecond merge candidate.

As another example, one among the merge candidates derived fromcandidate blocks positioned on the top of the current block may be setas the first merge candidate, and one among the merge candidates derivedfrom candidate blocks positioned on the left side may be set as thesecond merge candidate.

A combined prediction block may be acquired through a weighted sumoperation of the first prediction block derived from the first mergecandidate and the second prediction block derived based on the secondmerge candidate. At this point, the weighting value applied to the firstprediction block may be set to a value larger than the weighting valueapplied to the second prediction block.

Alternatively, weighting values may be determined based on motioninformation of the first merge candidate and motion information of thesecond merge candidate. For example, weighting values applied to thefirst prediction block and the second prediction block may be determinedbased on the difference in the output order of the reference picture andthe current picture. Specifically, as the difference in the output orderof the reference picture and the current picture increases, theweighting value applied to the prediction block may be set to a smallervalue.

Alternatively, weighting values applied to the first prediction blockand the second prediction block may be determined considering the sizesor the shapes of the candidate block used for deriving the first mergecandidate (hereinafter, referred to as the first candidate block) andthe candidate block used for deriving the second merge candidate(hereinafter, referred to as the second candidate block). For example, aweighting value applied to a prediction block derived from the firstcandidate block or the second candidate block having a shape similar tothat of the current block may be set to a large value. Contrarily, aweighting value applied to a prediction block derived from the firstcandidate block or the second candidate block having a shape dissimilarto that of the current block may be set to a small value.

FIG. 39 is a view showing an example in which weighting values appliedto prediction blocks are determined based on the shape of candidateblocks.

It is assumed that the current block is a non-square shape of which thewidth is greater than the height.

A first prediction block and a second prediction block may be derivedbased on the first merge candidate and the second merge candidate, and acombined prediction block may be generated based on a weighted sumoperation of the first prediction block and the second prediction block.At this point, weighting values applied to the first prediction blockand the second prediction block may be determined based on the shapes ofthe first candidate block and the second candidate block.

For example, in the example shown in FIG. 39 , the first candidate blockis a square shape, and the second candidate block is a non-square shapeof which the width is greater than the height. Since the shape of thesecond candidate block is the same as that of the current block, theweighting value applied to the second prediction block may be set to belarger than the weighting value applied to the first prediction block.For example, a weighting value of ⅝ may be applied to the secondprediction block, and a weighting value of ⅜ may be applied to the firstprediction block. Equation 33 shows an example of deriving a combinedprediction block based on a weighted sum operation of the firstprediction block and the second prediction block.P(x,y)=(3*P ₁(x,y)+5*P ₂(x,y))>>3  [Equation 33]

P (x, y) denotes a combined prediction block, P1 (x, y) denotes a firstprediction block, and P2 (x, y) denotes a second prediction block.

As another example, weighting values applied to the first predictionblock and the second prediction block may be determined based on theshape of the current block. For example, when the current block is anon-square shape of which the width is greater than the height, a largerweighting value may be applied to a prediction block generated based ona merge candidate derived based on a candidate block positioned on thetop of the current block among the first merge candidate and the secondmerge candidate. When both the first merge candidate and the secondmerge candidate are derived from the candidate blocks positioned on thetop of the current block, weighting values applied to the firstprediction block and the second prediction block may be set equally.Contrarily, when the current block is a non-square shape of which theheight is greater than the width, a larger weighting value may beapplied to a prediction block generated based on a merge candidatederived based on a candidate block positioned on the left side of thecurrent block among the first merge candidate and the second mergecandidate. When both the first merge candidate and the second mergecandidate are derived from the candidate blocks positioned on the leftside of the current block, weighting values applied to the firstprediction block and the second prediction block may be set equally.When the current block is a square shape, weighting values applied tothe first prediction block and the second prediction block may be setequally.

As another example, a weighting value applied to each prediction blockmay be determined based on the distance between the current block and acandidate block. Here, the distance may be derived based on an x-axiscoordinate difference, a y-axis coordinate difference from the currentblock, or a minimum value among them. A weighting value applied to aprediction block derived from a merge candidate having a small distancefrom the current block may be set to have a value larger than aweighting value applied to a prediction block derived from a mergecandidate having a large distance from the current block. For example,in the example shown in FIG. 37 , the first merge candidate is derivedfrom a neighboring block adjacent to the current block, and the secondmerge candidate is derived from a non-neighboring block that is notadjacent to the current block. In this case, since the x-axis distancebetween the first candidate block and the current block is smaller thanthe x-axis distance between the second candidate block and the currentblock, the weighting value applied to the first prediction block may beset to have a value larger than the weighting value applied to thesecond prediction block.

Alternatively, when both the first merge candidate and the second mergecandidate are derived from non-neighbor blocks, a larger weighting valuemay be assigned to a prediction block derived from a non-neighbor blockat a distance closer to the current block among the non-neighbor blocks.For example, in the example shown in FIG. 38 , since the y-axis distancebetween the first candidate block and the current block is smaller thanthe y-axis distance between the second candidate block and the currentblock, the weighting value applied to the first prediction block may beset to have a value larger than the weighting value applied to thesecond prediction block.

In the combined prediction mode combining a merge mode and a merge modeas described above, the merge mode may mean a merge mode based on atranslational motion model (hereinafter, referred to as a translationalmerge mode) or a merge mode based on an affine motion model(hereinafter, referred to as an affine merge mode). That is, motioncompensation prediction may be performed by combining a translationalmerge mode and a translational merge mode or by combining an affinemerge mode and an affine merge mode.

For example, when the first merge candidate is an affine mergecandidate, the second merge candidate may also be set as an affine mergecandidate. Here, the affine merge candidate indicates a case where themotion vector of a block including a reference candidate is an affinemotion vector. The second merge candidate may be specified by thevarious embodiments described above. For example, the second mergecandidate may be set as a neighboring merge candidate of the first mergecandidate. At this point, when the merge candidate adjacent to the firstmerge candidate is not encoded using an affine motion model, a mergecandidate encoded using an affine motion model may be set as the secondmerge candidate instead of the merge candidate.

Contrarily, when the first merge candidate is a non-affine mergecandidate, the second merge candidate may also be set as a non-affinemerge candidate. At this point, when a merge candidate adjacent to thefirst merge candidate is encoded using an affine motion model, a mergecandidate encoded using a translational motion model may be set as thesecond merge candidate instead of the merge candidate.

FIG. 40 is a view showing an example of setting a non-affine mergecandidate, instead of an affine merge candidate, as a second mergecandidate.

When the merge candidate at position A1 is specified as the first mergecandidate by merge_idx, merge candidate A2 having an index value largerthan that of the first merge candidate by 1 may be selected as thesecond merge candidate. At this point, when the first merge candidate isa non-affine merge candidate and the second merge candidate is an affinemerge candidate, the second merge candidate may be re-set. For example,among merge candidates having an index larger than merge_idx+1, anon-affine merge candidate having a smallest difference value withrespect to merge_idx+1 may be re-set as the second merge candidate. Forexample, in the example shown in FIG. 40 , it is shown that mergecandidate A3 having merge_idx+2 as an index is set as the second mergecandidate.

As another example, motion compensation prediction may be performed bycombining a translational merge mode and an affine merge mode. That is,any one among the first merge candidate and the second merge candidatemay be an affine merge candidate, and the other one may be a non-affinemerge candidate.

Integrated motion information may be derived based on the first mergecandidate and the second merge candidate, and motion compensationprediction for the current block may be performed based on theintegrated motion information. For example, a motion vector of thecurrent block may be derived based on an average operation or a weightedsum operation of the motion vector of the first merge candidate and themotion vector of the second merge candidate. At this point, theweighting value applied to the motion vector of the first mergecandidate and the weighting value applied to the motion vector of thesecond merge candidate may be determined by the embodiments describedabove.

When the first merge candidate is a non-affine merge candidate and thesecond affine merge candidate is an affine merge candidate, a motionvector of the current block may be derived by scaling the motion vectorof the second merge candidate. Equation 34 shows an example of derivinga motion vector of the current block.(mvX,mvY)=(mc0x,mv0y)+((mv1x,mv1y)>>M)  [Equation 34]

In Equation 34, (mvX, mvY) denotes the motion vector of the currentblock, (mv0x, mv0y) denotes the motion vector of the first mergecandidate, and (mv1x, mv1y) denotes the motion vector of the secondmerge candidate. M denotes a scaling parameter. M may be predefined inthe encoder and the decoder. Alternatively, the value of the scalingparameter M may be determined according to the size of the current blockor a candidate block. For example, when the width or the height of thesecond candidate block is greater than 32, M may be set to 3, and inother cases, M may be set to 2.

In the prediction mode in which a merge mode and a motion vectorprediction mode are combined, a first prediction block is generatedusing motion information derived from a merge candidate, and a secondprediction block is generated using a motion vector derived from amotion vector prediction candidate.

In the motion vector prediction mode, a motion vector predictioncandidate may be derived from a neighboring block adjacent to thecurrent block or a collocated block in a collocated picture. Thereafter,any one among a plurality of motion vector prediction candidates may bespecified, and the specified motion vector prediction candidate may beset as the motion vector predictor of the current block. Thereafter, amotion vector of the current block may be derived by adding the motionvector predictor of the current block and a motion vector differencevalue.

In the prediction mode in which a merge mode and a motion vectorprediction mode are combined, the merge candidate and the motion vectorprediction candidate may be derived from the same candidate block. Forexample, when the merge candidate is specified by merge_idx, a motionvector of a candidate block used for deriving the specified mergecandidate may be set as the motion vector predictor. Alternatively, whenthe motion vector prediction candidate is specified by mvp_flag, a mergecandidate derived from a candidate block used for deriving the specifiedmerge candidate may be selected.

Alternatively, the candidate block used for deriving the merge candidateand the candidate block used for deriving the motion vector predictioncandidate may be different. For example, when a merge candidate derivedfrom a candidate block positioned on the top of the current block isselected, it may be set to select a motion vector prediction candidatederived from a candidate block positioned on the left side of thecurrent block.

Alternatively, when the merge candidate selected by index informationand the motion vector prediction candidate selected by index informationare derived from the same candidate block, the motion vector predictioncandidate may be replaced with a motion vector prediction candidatederived from a neighboring candidate block adjacent to the candidateblock, or the merge candidate may be replaced with a merge candidatederived from a candidate block adjacent to the candidate block.

FIG. 41 is a view showing an example in which a merge candidate isreplaced.

In the example shown in FIG. 41 (a), it is shown that a merge candidateand a motion vector prediction candidate derived from the candidateblock at position A2 are selected. As shown in the figure, when a mergecandidate and a motion vector prediction candidate are derived from thesame candidate block, a merge candidate or a motion vector predictioncandidate derived from a candidate block adjacent to the candidate blockmay be used instead of the merge candidate or the motion vectorprediction candidate. For example, as shown in the example of FIG. 41(b), a merge candidate at position A1 may be used instead of the mergecandidate at position A2.

A first prediction block may be derived based on the merge candidate ofthe current block, and a second prediction block may be derived based onthe motion vector prediction candidate. Thereafter, a combinedprediction block may be derived through a weighted sum operation of thefirst prediction block and the second prediction block. At this point,the weighting value applied to the second prediction block generatedusing the motion vector prediction mode may be set to a value largerthan the weighting value applied to the first prediction block generatedusing the merge mode.

A derived residual picture may be derived by subtracting a predictionvideo from an original video. At this point, when the residual video ischanged to the frequency domain, subjective video quality of the videois not significantly lowered although the high-frequency componentsamong the frequency components are removed. Accordingly, when values ofthe high-frequency components are converted to be small or the values ofthe high-frequency components are set to 0, there is an effect ofincreasing the compression efficiency without generating significantvisual distortion. By reflecting this characteristic, the current blockmay be transformed to decompose a residual video into two-dimensionalfrequency components. The transform may be performed using a transformtechnique such as Discrete Cosine Transform (DCT) or Discrete SineTransform (DST).

The DCT decomposes (or transforms) a residual video into two-dimensionalfrequency components using a cosine transform, and the DST decomposes(or transforms) a residual video into two-dimensional frequencycomponents using a sine transform. As a result of transforming theresidual video, the frequency components may be expressed as a basisvideo. For example, when DCT transform is performed on a block of an N×Nsize, as many basic pattern components as N² may be acquired. The sizeof each of the basic pattern components included in a block of an N×Nsize may be acquired through the transform. According to a transformtechnique used therefor, the value of the basic pattern component may bereferred to as a DCT coefficient or a DST coefficient.

Transform technique DCT is mainly used to transform a video in whichmany non-zero low-frequency components are distributed. The transformtechnique DST is mainly used for videos in which many high-frequencycomponents are distributed.

The residual video may be transformed using a transform technique otherthan the DCT or the DST.

Hereinafter, transform of a residual video into two-dimensionalfrequency components will be referred to as two-dimensional videotransform. In addition, the size of the basic pattern componentsacquired as a result of the transform is referred to as a transformcoefficient. For example, the transform coefficient may mean a DCTcoefficient or a DST coefficient. When both first transform and secondtransform described below are applied, the transform coefficient maymean the size of a basic pattern component generated as a result of thesecond transform.

The transform technique may be determined for each block. The transformtechnique may be determined based on at least one among the predictionencoding mode of the current block, the shape of the current block, andthe size of the current block. For example, when the current block isencoded in the intra prediction mode and the size of the current blockis smaller than N×N, transform may be performed using the transformtechnique DST. Contrarily, when the above conditions are not satisfied,transform may be performed using the transform technique DCT.

The two-dimensional video transform may not be performed for some blocksof the residual video. Not performing the two-dimensional videotransform may be referred to as a transform skip. When the transformskip is applied, quantization may be applied to residual coefficientsthat have not been transformed.

After the current block is transformed using DCT or DST, the transformedcurrent block may be transformed again. At this point, the transformbased on DCT or DST may be defined as a first transform, andtransforming again a block to which the first transform is applied maybe defined as a second transform.

The first transform may be performed using any one among a plurality oftransform core candidates. For example, the first transform may beperformed using any one among DCT2, DCT8, or DCT7.

Different transform cores may be used for the horizontal direction andthe vertical direction. Information indicating combination of atransform core of the horizontal direction and a transform core of thevertical direction may be signaled through a bitstream.

Units for performing the first transform and the second transform may bedifferent. For example, the first transform may be performed on an 8×8block, and the second transform may be performed on a subblock of a 4×4size among the transformed 8×8 block. At this point, the transformcoefficients of the residual regions that has not been performed thesecond transform may be set to 0.

Alternatively, the first transform may be performed on a 4×4 block, andthe second transform may be performed on a region of an 8×8 sizeincluding the transformed 4×4 block.

Information indicating whether or not the second transform has beenperformed may be signaled through a bitstream.

The decoder may perform an inverse transform of the second transform (asecond inverse transform), and may perform an inverse transform of thefirst transform (a first inverse transform) on a result of the inversetransform. As a result of performing the second inverse transform andthe first inverse transform, residual signals for the current block maybe acquired.

Quantization is for reducing the energy of a block, and the quantizationprocess includes a process of dividing a transform coefficient by aspecific constant value. The constant value may be derived by aquantization parameter, and the quantization parameter may be defined asa value between 1 and 63.

When the encoder performs transform and quantization, the decoder mayacquire a residual block through inverse quantization and inversetransform. The decoder may acquire a reconstructed block for the currentblock by adding a prediction block and the residual block.

When a reconstructed block of the current block is acquired, loss ofinformation occurring in the quantization and encoding process may bereduced through in-loop filtering. An in-loop filter may include atleast one among a deblocking filter, a sample adaptive offset filter(SAO), and an adaptive loop filter (ALF). Hereinafter, a reconstructedblock before the in-loop filter is applied is referred to as a firstreconstructed block, and a reconstructed block after the in-loop filteris applied is referred to as a second reconstructed block.

The second reconstructed block may be acquired by applying at least oneamong the deblocking filter, the SAO, and the ALF to the firstreconstructed block. At this point, the SAO or the ALF may be appliedafter the deblocking filter is applied.

The deblocking filter is for mitigating degradation of video quality(blocking artifact) at the boundary of a block, which occurs asquantization is performed on individual blocks. In order to apply thedeblocking filter, a block strength (BS) between the first reconstructedblock and a neighboring reconstructed block may be determined.

FIG. 42 is a flowchart illustrating a process of determining blockstrength.

In the example shown in FIG. 42 , P denotes a first reconstructed block,and Q denotes a neighboring reconstructed block. Here, the neighboringreconstructed block may be a block adjacent to the left side or the topside of the current block.

In the example shown in FIG. 42 , it is shown that the block strength isdetermined considering the prediction encoding modes of P and Q, whethera non-zero transform coefficient is included, whether inter predictionis performed using the same reference picture, and whether thedifference value of motion vectors is larger than or equal to athreshold value.

Whether or not to apply the deblocking filter may be determined based onthe block strength. For example, when the block strength is 0, filteringmay not be performed.

The SAO is for mitigating a ringing phenomenon (ringing artifact) thatoccurs as quantization is performed in the frequency domain. The SAO maybe performed by adding or subtracting an offset determined consideringthe pattern of the first reconstructed video. The method of determiningthe offset includes an edge offset (EO) or a band offset (BO). EOdenotes a method of determining an offset of a current sample accordingto the pattern of surrounding pixels. BO denotes a method of applying acommon offset to a set of pixels having similar brightness values in aregion. Specifically, pixel brightness may be divided into 32 equalsections, and pixels having similar brightness values may be set as oneset. For example, four adjacent bands among 32 bands may be set as onegroup, and the same offset value may be applied to the samples belongingto the four bands.

The ALF is a method of generating a second reconstructed video byapplying a filter having a predefined size/shape to the firstreconstructed video or a reconstructed video to which a deblockingfilter has been applied. Equation 35 shows an example of applying theALF.

$\begin{matrix}{{R^{\prime}\left( {i,j} \right)} = {{\sum}_{k = {- \frac{N}{2}}}^{\frac{N}{2}}{\sum}_{l = {- \frac{N}{2}}}^{\frac{N}{2}}{{f\left( {k,l} \right)} \cdot {R\left( {{i + k},\ {j + l}} \right)}}}} & \left\lbrack {{Equation}35} \right\rbrack\end{matrix}$

Any one among predefined filter candidates may be selected by the unitof a picture, a coding tree unit, a coding block, a prediction block, ora transform block. Each of the filter candidates may be different ineither the size or the shape.

FIG. 43 is a view showing predefined filter candidates.

As shown in the example of FIG. 42 , at least one among 5×5, 7×7 and 9×9diamond shapes may be selected.

Only a diamond shape of a 5×5 size may be used for a chroma component.

Applying the embodiments described above focusing on a decoding processor an encoding process to an encoding process or a decoding process isincluded in the scope of the present disclosure. Changing theembodiments described in a predetermined order in an order differentfrom the described order is also included in the scope of the presentdisclosure.

Although the embodiments above have been described based on a series ofsteps or flowcharts, this does not limit the time series order of thepresent disclosure, and may be performed simultaneously or in adifferent order as needed. In addition, each of the components (e.g.,units, modules, etc.) constituting the block diagram in the embodimentsdescribed above may be implemented as a hardware device or software, ora plurality of components may be combined to be implemented as a singlehardware device or software. The embodiments described above may beimplemented in the form of program commands that can be executed throughvarious computer components and recorded in a computer-readablerecording medium. The computer-readable recording medium may includeprogram commands, data files, data structures and the like independentlyor in combination. The computer-readable recording medium includes, forexample, magnetic media such as a hard disk, a floppy disk and amagnetic tape, optical recording media such as a CD-ROM and a DVD,magneto-optical media such as a floptical disk, and hardware devicesspecially configured to store and execute program commands, such as aROM, a RAM, a flash memory and the like. The hardware devices describedabove can be configured to operate using one or more software modules toperform the process of the present disclosure, and vice versa.

INDUSTRIAL APPLICABILITY

The present disclosure can be applied to an electronic device thatencodes and decodes a video.

What is claimed is:
 1. A video decoding method, comprising: generating amerge candidate list for a first block; selecting one among mergecandidates included in the merge candidate list; and performing motioncompensation for the first block based on motion information of theselected merge candidate; wherein an inter-region merge candidateincluded in an inter-region motion information list is added to themerge candidate list based on the number of spatial merge candidates andtemporal merge candidates included in the merge candidate list; themerge candidates comprise a first merge candidate and a second mergecandidate, and the first merge candidate and the second merge candidateare included in the merge candidate list for the first block; and afirst prediction block is generated using the first merge candidate, asecond prediction block is generated using a second merge candidate, andthe prediction block for the first block is generated based on aweighted sum operation of the first prediction block and the secondprediction block.
 2. The method according to claim 1, wherein theinter-region motion information list includes an inter-region mergecandidate derived based on motion information of a block decoded beforethe first block.
 3. The method according to claim 1, wherein when thefirst block is included in a merge processing area, a temporary mergecandidate derived based on motion information of the first block isadded to a temporary motion information list, and when all blocksincluded in the merge processing area are decoded, the temporary mergecandidate is added in the inter-region motion information list.
 4. Themethod according to claim 1, wherein based on determination regardingwhether one inter-region merge candidate included in the inter-regionmotion information list is the same as at least one merge candidateincluded in the merge candidate list, it is determined whether to addthe one inter-region merge candidate to the merge candidate list.
 5. Themethod according to claim 4, wherein the determination is performed bycomparing at least one merge candidate of which the index value issmaller than or equal to a threshold value with the one inter-regionmerge candidate.
 6. The method according to claim 4, wherein when it isdetermined that there is a merge candidate the same as the oneinter-region merge candidate, the one inter-region merge candidate isnot added to the merge candidate list, and based on a result ofdetermining whether another inter-region merge candidate included in theinter-region motion information list is the same as at least one mergecandidate included in the merge candidate list, it is determined whetherto add the another inter-region merge candidate to the merge candidatelist, and no determination regarding whether the another inter-regionmerge candidate is the same as the merge candidate that is the same asthe one inter-region merge candidate is performed.
 7. The methodaccording to claim 1, wherein when an inter-region merge candidate thesame as motion information of the first block exists in the mergecandidate list, an index assigned to the inter-region merge candidate inthe inter-region motion information list is updated to a maximum value.8. The method according to claim 4, wherein the determination isperformed by comparing at least one merge candidate of which the indexvalue is larger than a threshold value with the one inter-region mergecandidate.
 9. The method according to claim 4, wherein the determinationis performed by comparing a merge candidate derived from a block at aspecific position with the one inter-region merge candidate, wherein thespecific position includes at least one of a top-right neighboring blockor a bottom-left neighboring block of the first block.
 10. The methodaccording to claim 1, wherein performing motion compensation for thefirst block comprises: performing motion compensation prediction for thefirst block using a plurality of merge candidates.
 11. The methodaccording to claim 1, wherein index information merge_idx of the firstmerge candidate and index information merge_2nd_idx of the second mergecandidate are obtained by analyzing a bitstream.
 12. The methodaccording to claim 11, wherein when a value of index informationmerge_2nd_idx is equal to or greater than a value of index informationmerge_idx, a value of an index of the second merge candidate is obtainedby adding 1 to the value of index information merge_2nd_idx.
 13. A videoencoding method, comprising: generating a merge candidate list for afirst block; selecting one among merge candidates included in the mergecandidate list; and performing motion compensation for the first blockbased on motion information of the selected merge candidate; wherein aninter-region merge candidate included in an inter-region motioninformation list is added to the merge candidate list based on thenumber of spatial merge candidates and temporal merge candidatesincluded in the merge candidate list; the merge candidates comprise afirst merge candidate and a second merge candidate, and the first mergecandidate and the second merge candidate are included in the mergecandidate list for the first block; and a first prediction block isgenerated using the first merge candidate, a second prediction block isgenerated using a second merge candidate, and the prediction block forthe first block is generated based on a weighted sum operation of thefirst prediction block and the second prediction block.
 14. The methodaccording to claim 13, wherein the inter-region motion information listincludes an inter-region merge candidate derived based on motioninformation of a block encoded before the first block.
 15. The methodaccording to claim 13, wherein when the first block is included in amerge processing area, a temporary merge candidate derived based onmotion information of the first block is added to a temporary motioninformation list, and when all blocks included in the merge processingarea are encoded, the temporary merge candidate is added in theinter-region motion information list.
 16. The method according to claim13, wherein based on determination regarding whether one inter-regionmerge candidate included in the inter-region motion information list isthe same as at least one merge candidate included in the merge candidatelist, it is determined whether to add the one inter-region mergecandidate to the merge candidate list.
 17. The method according to claim16, wherein the determination is performed by comparing at least onemerge candidate of which the index value is smaller than or equal to athreshold value with the one inter-region merge candidate.
 18. Themethod according to claim 13, wherein index information merge_idx of thefirst merge candidate and index information merge_2nd_idx of the secondmerge candidate are signaled through a bitstream, respectively.
 19. Avideo decoding apparatus, comprising a memory and a processor, whereinthe memory is configured to store a computer program capable of runningin the processor; and the processor is configured to run the computerprogram to execute a video decoding method, the method comprising:generating a merge candidate list for a first block; selecting one amongmerge candidates included in the merge candidate list; and performingmotion compensation for the first block based on motion information ofthe selected merge candidate, wherein an inter-region merge candidateincluded in an inter-region motion information list is added to themerge candidate list based on the number of spatial merge candidates andtemporal merge candidates included in the merge candidate list; themerge candidates comprise a first merge candidate and a second mergecandidate, and the first merge candidate and the second merge candidateare included in the merge candidate list for the first block; and afirst prediction block is generated using the first merge candidate, asecond prediction block is generated using a second merge candidate, andthe prediction block for the first block is generated based on aweighted sum operation of the first prediction block and the secondprediction block.
 20. A video encoding apparatus, comprising a memoryand a processor, wherein the memory is configured to store a computerprogram capable of running in the processor; and the processor isconfigured to run the computer program to execute the video encodingmethod of claim 13.